1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| public class Day { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()){ int year = input.nextInt(); int month = input.nextInt(); int day = input.nextInt(); int daysInYear = getDaysInYear(year, month, day); System.out.println(daysInYear); } }
private static int getDaysInYear(int year, int month, int day) {
int total = 0;
switch (month-1){ case 11:total += 30; case 10:total += 31; case 9:total += 30; case 8:total += 31; case 7:total += 31; case 6:total += 30; case 5:total += 31; case 4:total += 30; case 3:total += 31; case 2:total += 28; case 1:total += 31; case 0:break; } if (isR(year)){ total++; } total +=day; return total; }
private static boolean isR(int year){ if(year%400==0||(year%4==0 && year%100!=0)){ return true; } return false; }
}
|