第一篇博客,尝试
public static void main(String[] args)
{
System.out.println("Hello CSDN!");
}
更新,实现一个简单的日历,打印出本月的日历并用"*"号标记当天的日期。
package hellofirst;
import java.time.*;
public class CalendarTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
LocalDate date = LocalDate.now();
int month = date.getMonthValue();
int today = date.getDayOfMonth();
date = date.minusDays(today - 1); //to the start of the month
DayOfWeek weekday = date.getDayOfWeek();
int value = weekday.getValue(); //得到星期几
System.out.println(month + "月:");
System.out.println("Mon Tue Wed Thu Fri Sat Sun");
for (int i = 1;i<value;i++)
System.out.print(" ");
while (date.getMonthValue() == month)
{
System.out.printf("%3d", date.getDayOfMonth());
if (date.getDayOfMonth() == today)
System.out.print("*"); // show the current day
else
System.out.print(" ");
date = date.plusDays(1);
if (date.getDayOfWeek().getValue() == 1)
System.out.println();//
}
if(date.getDayOfWeek().getValue() != 1 )
System.out.println();
}
}
以后会在这多记笔记了,不在知乎记笔记了 。