打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Java实现给定年份和月份,输出该月的天数
闰年的条件(满足之一即可):(1)能被4整除,但不能被100整除;(2)能被400整除
public static int getDays(int year, int month) {
int days = 0;
boolean isLeapYear = false;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
System.out.println("--------------------闰年-------------------");
isLeapYear = true;
} else {
System.out.println("--------------------非闰年-------------------");
isLeapYear = false;
}
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 2:
if (isLeapYear) {
days = 29;
} else {
days = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
default:
System.out.println("error!!!");
break;
}
return days;
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
java 计算时间段
万年历(C语言)
JavaHomeWorkList-Java语言程序设计(基础篇)第十版第三章部分答案
c语言输入年月,显示当月多少天
判断闰年平年
开关语句
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服