"Program 4"
Title: Enter a certain day of the year, judging the day is the first of the year?
1. Procedure analysis: Take March 5 as an example, should first add up the first two months, and then add 5 days that is the first day of the year, special cases, leap years and enter the month greater than 3 o'clock need to consider more than one day.
2. Program Source code:
1 ImportJava.util.Scanner;2 3 /*4 "Program 4"5 Title: Enter a certain day of the year, judging the day is the first of the year? 6 procedure Analysis: Take March 5 as an example, should first add up the first two months, and then add 5 days that is the first day of the year. 7 special case, leap year and the input month is greater than 3 o'clock need to consider extra day. 8 */9 Ten Public classJava04 { One A Public Static voidMain (string[] args) { -System.out.print ("Please enter the month and day to be queried, separated by a space, example 2012 2 22:"); -Scanner Scanner =NewScanner (system.in); the intYear =scanner.nextint (); - intmonth =scanner.nextint (); - intDay =scanner.nextint (); - scanner.close (); + int[]days; - if((year%4==0&&year%100!=0) | | Year%400==0){ +days=New int[]{0,31,60,91,121,152,182,213,244,274,305,335}; A}Else{ atdays=New int[]{0,31,59,90,120,151,181,212,243,273,304,334}; - } -System.out.print (Year + "years" + month + "Month" + Day + "date" + "+ (Days[month-1] + day) +" Days "); - } -}
go to Java-100 blog Blog Statement
Java rewrite "C Classic 100 Questions"--04