题目描述
描述
输入任意年份,输出该年份各月天数(请使用 Calendar 类中的方法)
输入描述:
任意年份(int类型整数)
输出描述:
x年1月:yy天
x年2月:yy天
x年3月:yy天
x年4月:yy天
x年5月:yy天
x年6月:yy天
x年7月:yy天
x年8月:yy天
x年9月:yy天
x年10月:yy天
x年11月:yy天
x年12月:yy天(x为输入的任意年份,yy为当月天数)
代码
import java.util.Calendar;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int year = console.nextInt();
//write your code here......
Calendar instance=Calendar.getInstance();
for (int month = 1; month <= 12; month++) {
instance.set(year,month,0);
System.out.println(year + "年" + month + "月:" + instance.get(Calendar.DAY_OF_MONTH) + "天" );
}
}
}
结果