试试,不懂追问
public static void main(String args[]){
//建立键盘输入:
System.out.println("请输入年份:");
Scanner scanner = new Scanner(System.in);
String yearStr = scanner.nextLine();
Calendar cal1 = Calendar.getInstance();
for(int month = 0 ; month<12 ; month ++){
cal1.set(Integer.parseInt(yearStr), month, 1, 0, 0, 0);
System.out.println((month+1)+"月天数为:"+cal1.getActualMaximum(Calendar.DAY_OF_MONTH));
}
}