public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int y = in.nextInt();
int m = in.nextInt();
int[] d = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
if((y%4==0&y%100!=0)||y%400==0) {
d[1]+=1;
System.out.println(d[y-1]);
}
else {
System.out.println(d[y-1]);
}
}
}
月份为2且为闰年时,输出的天数还是28,这是为什么?
月份为2且为闰年时,输出的天数还是28,这是为什么?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注 改好了,顺便帮你简化了一下代码,希望采纳
public class Demo { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入年份:"); int y = in.nextInt(); System.out.println("请输入月份:"); int m = in.nextInt(); int[] d = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if ((y % 4 == 0 & y % 100 != 0) || y % 400 == 0) { d[1] += 1; } System.out.println(d[m - 1]); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程
- ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
- ¥15 Centos / PETSc / PETGEM
- ¥15 centos7.9 IPv6端口telnet和端口监控问题
- ¥120 计算机网络的新校区组网设计
- ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
- ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
- ¥20 海浪数据 南海地区海况数据,波浪数据