Enter a certain day of the year, judging the day is the first of the year?
1Scanner SC2 =NewScanner (system.in);2System.out.println ("Please enter the year:");3 intYear=sc2.nextint ();4System.out.println ("Please enter month:");5 intMonth=sc2.nextint ();6System.out.println ("Please Enter Date:");7 intday=sc2.nextint ();8 intzday=0;//Define total Days9 Booleanisrn;//judgment is a leap year returns trueTen if((year%4==0&&year%100!=0) | | Year%400==0){ Oneisrn=true; A}Else{ -isrn=false; - } the for(inti=1;i<month;i++){ - Switch(i) { - Case1: - Case3: + Case5: - Case7: + Case8: A Case10: at Case12: -Zday+=31; - Break; - Case2: - if(ISRN) { -zday+=29; in}Else{ -Zday+=28; to } + Break; - Case4: the Case6: * Case9: $ Case11:Panax NotoginsengZday+=30; - Break; the default: +System.out.println ("Incorrect month input, please re-enter!") "); A } the } +zday+=Day ; -System.out.println (month+ "Month" +day+ "Day, is the" +year+ "year" +zday+ "day. ");
Results:
Statement Exercises 4