已知某年某月,请输出这个月共有多少天(switch语句)

来源:互联网 发布:淘宝网餐桌 编辑:程序博客网 时间:2024/05/16 06:18
package com.zhidi;


public class Lianxi08 {


public static void main(String[] args) {
// 已知某年某月,请输出这个月共有多少天。(switch语句)

int year = 2012;
int month = 2;

switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(year+"年"+month+"月一共有31天");
break;
case 4:
case 6:
case 9:
case 11:
System.out.println(year+"年"+month+"月一共有30天");
break;
case 2:
if(year%4==0 && year%100!=0 || year%400==0){
System.out.println(year+"年"+month+"月一共有29天");
}else{
System.out.println(year+"年"+month+"月一共有28天");
}
break;
default:
System.out.println("输入错误");
}


}


}
0 0
原创粉丝点击