从键盘任意输入一个年份,和一个月份,输出该年这个月份有多少天,用程序实现 比如: 输入年份: 2021 输入月份: 12 输出:2021年12月份共

public static void main(String[] args) {
    System.out.println("输入年份:");
    Scanner s = new Scanner(System.in);//键盘扫描器
    int year = s.nextInt();
    System.out.println("输入月份");
    int month = s.nextInt();
    switch (month){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            System.out.println(year+"年"+month+"月份共:"+31+"天");
            break;
        case 2:if (year%400==0||(year%4==0&&year%100!=0))//二月判别器
        {
            System.out.println(year+"年"+month+"月份共:"+29+"天");

        }else {
            System.out.println(year+"年"+month+"月份共:"+28+"天");
        }
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            System.out.println(year+"年"+month+"月份共:"+30+"天");
            break;
    }

}

版权声明:本文为LS460000原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。