用Java实现编程输入年月,判断平年、闰年和当月天数

用Java实现编程输入年月,判断平年、闰年和当月天数项目 用 Java 实现编程输入年月 判断平年 闰年和当月天数 时间 2019 9 8 作者 郑翰林 import java util Scanner public class Exercies6 public static void main String args Scanner scan new

大家好,我是讯享网,很高兴认识大家。
/ * 项目:用Java实现编程输入年月,判断平年、闰年和当月天数 * 时间:2019/9/8 * 作者:郑翰林 */ import java.util.Scanner; public class Exercies6 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int days=0; System.out.print("请输入年号:"); int year = scan.nextInt(); System.out.print("请输入月份:"); int month=scan.nextInt(); if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { // 是闰年 System.out.print(year + "年是闰年!"); } else { // 不是闰年 System.out.print(year + "年不是闰年,是平年!"); } //先判断闰年,然后的话再考虑1-12月某个月是多少天 switch(month){ case 1:case 3:case 5:case 7:case 8:case 10:case 12:days = 31;break; case 4:case 6:case 9:case 11:days = 30;break; case 2:{ if(year%400==0 || year%4==0 && year%100!=0){ days = 29; }else{ days = 28; } } } System.out.println(); System.out.println(year+"年,"+month+"月,有"+days+"天"); } } 

讯享网
小讯
上一篇 2025-04-09 19:28
下一篇 2025-03-29 13:55

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/90208.html