当前位置:首页 » 编程软件 » 判月编程

判月编程

发布时间: 2023-08-27 21:59:17

java编程 判断月份,判断天数

importjava.util.*;
/**
*
*这里没有对输入非数字的数进行处理!
*/
publicclassShell{
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
inty=0;
intn=0;
//输入年份,用于判断闰年!
System.out.println("请输入年份:");
y=sc.nextInt();
System.out.println("请输入月份:");
n=sc.nextInt();
switch(n){
case1:
case3:
case5:
case7:
case8:
case10:
case12:
System.out.println(n+"月份有:31天");
break;
//对于2月份需要判断是否为闰年
case2:
if((y%4==0&&y%100!=0)||(y%400==0)){
System.out.println(n+"月份有:29天");
break;
}else{
System.out.println(n+"月份有:28天");
break;
}
case4:
case6:
case9:
case11:
System.out.println(n+"月份有:30天");
break;
default:
System.out.println("请输入正确的年份和月份");
break;
}
}
}

热点内容
怎么看自己微信密码 发布:2025-03-15 07:53:58 浏览:789
androidchecked 发布:2025-03-15 07:50:22 浏览:548
百度carplay怎么连接安卓手机 发布:2025-03-15 07:49:39 浏览:22
捕捉图片上传 发布:2025-03-15 07:49:01 浏览:794
手机内核升级编译 发布:2025-03-15 07:43:22 浏览:235
好java学校 发布:2025-03-15 07:43:22 浏览:134
搭建web服务器面试 发布:2025-03-15 07:43:16 浏览:263
sql查询as 发布:2025-03-15 07:36:04 浏览:208
ibmv7000存储 发布:2025-03-15 07:31:39 浏览:410
哈弗曼算法 发布:2025-03-15 07:31:35 浏览:577