day_09 Package; / * The calculation of the date entered in the date of the days of the year * / Import java.util.Scanner; public class the Test { public static void main (String [] args) { // enter dates Scanner input = new Scanner (System.in); System.out.print ( "enter date:"); int year = input.nextInt (); int = month The input.nextInt (); int = input.nextInt day (); / / number of days corresponding to int = sumday getSumDay (year, month the, day); // output System.out.println (year + "in" + + month the "month" day + + "day" + "is the" year + + "in the first" + sumday + "days"); } Private getSumDay static int (int year,int month, int day) { int = 0 days; for (int i = 1; i <month; i++) { days += getMonthDay(year,i); } return days+day; } private static int getMonthDay(int year,int month) { int day=0; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 11: day=31; break; case 2: //如果是闰年:29天,否则是:28天 day=getDay(year); break; case 4: case 6: case 9: case 12: day=30; break; } return day; } private static int getDay(int year) { if(year%4==0 || (year%100==0 && year%400==0)) return 29; else return 28; } }