解题思路:年份分闰年和平年,只会影响2月份,其他月份在每年的规律都一样所以我们这里选择用switch
/*
接收用户输入的年份和月份,判断该年该月共有多少天
*/
import ;
public class Demo02 {
public static void main(String[] args) {
Scanner sc = new Scanner();
("请输入年份:");
int year = ();
("请输入月份:");
int month = ();
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
(year+"年"+month+"月:31天");
break;
case 4:
case 6:
case 9:
case 11:
(year+"年"+month+"月:30天");
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
(year+"年"+month+"月:29天");
}else{
(year+"年"+month+"月:28天");
}
break;
}
}
}