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

判月编程

发布时间: 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;
}
}
}

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:566
制作脚本网站 发布:2025-10-20 08:17:34 浏览:855
python中的init方法 发布:2025-10-20 08:17:33 浏览:555
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:733
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:656
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:975
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:227
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:87
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:777
python股票数据获取 发布:2025-10-20 07:39:44 浏览:683