PackageCom.xiaowu.demo;/*** Enter a certain month of the year, judging the day is the first of the year? * * * @authorWQ **/ Public classDemo14 { Public Static voidMain (string[] args) {year (2017, 6, 5); } /*** * Common year February 28 days, leap year February 29 days. * Year number (last two bits not 00) can be divisible by 4 is a leap year (such as 1988, 1996), the number of years (the last two digits is 00) can be divisible by 400 is also a leap year (such as 2000, 4000). The rest is common year. * * * * @paramYear *@paramMonth *@param Day*/ Public Static voidYearintYearintMonthintDay ) { intd = 0; intDays = 0; if(Year < 0 | | Month < 0 | | month > | |-day < 0 | | Day > 31) {System.out.println ("Input error, please re-enter!" "); } for(inti = 1; I < month; i++) { Switch(i) { Case1: Case3: Case5: Case7: Case8: Case10: Case12: Days= 31; Break; Case4: Case6: Case9: Case11: Days= 30; Break; Case2: if(Year% 400 = = 0) | | (year% 4 = = 0 && Year% 100! = 0) ) { days= 29; } Else{ days= 28; } Break; } d+=Days ; } System.out.println ( year+ "Years" + month + "Month" + Day + "date" + year + "+" + (d + days) + "Tian". "); }}
Java Common Algorithm questions (14)