// 根据年份判断是否是闰月,每月有多少天 |
int m, c = 0 , month; |
Scanner sc = new Scanner(System.in); |
System.out.print( "输入年份" ); |
m = sc.nextInt(); |
if (m % 4 == 0 ) { |
System.out.print(m + "年是闰年。" ); |
c = 29 ; |
} else { |
System.out.print(m + "年不是闰年。" ); |
c = 28 ; |
} |
System.out.print( "\n输入月份" ); |
month = sc.nextInt(); |
if (month == 2 ) { |
System.out.print(month + "月有" + c + "天" ); |
} else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 ) { |
System.out.print(month + "月有31天" ); |
} else { |
System.out.print(month + "月有30天" ); |
} |