题解 | #输出某一年的各个月份的天数#
输出某一年的各个月份的天数
http://www.nowcoder.com/practice/6cc6d87805cc4e32866be0541998d8c9
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();
//获取Calendar的实例
Calendar calendar=Calendar.getInstance();
//循环遍历所有的月份
for(int month=1;month<=12;month++){
//设置年、月、日
calendar.set(year,month,0);
//输出对应年份各个月的天数
System.out.println(year+"年"+month+"月:"+calendar.getActualMaximum(Calendar.DATE)+"天");
}
}
}

查看23道真题和解析