Demand: Get any one year, how many days in February
- 1. keyboard input in any year
- 2. Set the calendar object of year, month, day
year: from keyboard input
month: Set to March, when the month starts from 0, so the value of 2 set
day: 1st set - 3. March 1 to push forward, is the last day of February
- 4. Access to this day output
public class CalendarTest {
public static void main(String[] args) {
//输入任意年份
Scanner sc = new Scanner(System.in);
System.out.println("请输入任意年份:");
int year = sc.nextInt();
Calendar c = Calendar.getInstance();
c.set(year,2,1);
c.add(Calendar.DATE, -1);
int date = c.get(Calendar.DATE);
System.out.println(year+"年"+"二月有"+date+"天");
}
}