JAVA基本语法-switch--从键盘上输入year、month和day,要求通过程序输出该日期为该年的第几天

从键盘上输入year、month和day,要求通过程序输出该日期为该年的第几天

import java.util.Scanner;
class Test{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入year");
        int year=scan.nextInt();
        System.out.println("请输入month");
        int month=scan.nextInt();
        System.out.println("请输入day");
        int day=scan.nextInt();
        int sumDays=0;
        switch(month){
            case 12: sumDays+=30;
            case 11: sumDays+=31;
            case 10: sumDays+=30;
            case 9:  sumDays+=31;
            case 8:  sumDays+=31;
            case 7:  sumDays+=30;
            case 6:  sumDays+=31;
            case 5:  sumDays+=30;
            case 4:  sumDays+=31;
            case 3:  
                if(( year%4==0 && year%100!=0 )|| (year%400==0) ){
                    sumDays+=29;
                }
                else{
                    sumDays+=28;
                }
            case 2:  sumDays+=31;
            case 1:  sumDays+=day;
        }
        System.out.println(sumDays);
    }
}
posted @ 2022-01-03 11:14  ice--cream  阅读(426)  评论(0编辑  收藏  举报