Packagestudy01;ImportJava.util.Scanner; Public classTestday {/** Enter 2017 year month and day: month=?,day=? The date of the output input is the day of 2017, using switch to complete*/ Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); System.out.print ("Month="); intmonth =Sc.nextint (); System.out.print ("Day="); intDay =Sc.nextint (); intDays = 0; Switch(month) { Case12: Days+ = 30; Case11: Days+ = 31; Case10: Days+ = 30; Case9: Days+ = 31; Case8: Days+ = 31; Case7: Days+ = 30; Case6: Days+ = 31; Case5: Days+ = 30; Case4: Days+ = 31; Case3: Days+ = 28; Case2: Days+ = 31; Case1: Days+=Day ; } if(days>365) {System.out.println ("You've entered it for more than 365 days."); }Else{System.out.println ("First" + Days + "Day"); } }}
The results of the output are as follows:
Month=12
Day=31
No. 365 Day
Based on the month and day entered, the day of the year is calculated.