public class Switch01 {
/**
* 实现输出指定的年月的那个月有多少天?
*
*/
public static void main(String[] args) {
int year = 2020;
int month = 2;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(31);
break;
case 4:
case 6:
case 9:
case 11:
System.out.println(30);
break;
default:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
System.out.println(29);
}else
System.out.println(28);
break;
}
}
}
switch输出指定年月的的月份的天数
最新推荐文章于 2024-04-02 00:23:47 发布