package dayprint; import java.util.*; public class DayPrint { public static void main(String[] args) { int whichDay = 0; Scanner sc = new Scanner(System.in); System.out.println("曜日の日付判定を致します。日付を入力して下さい。"); System.out.print("年: "); int inputYear = Integer.parseInt(sc.nextLine()); System.out.print("月: "); int inputMonth = Integer.parseInt(sc.nextLine()); System.out.print("日: "); int inputDay = Integer.parseInt(sc.nextLine()); int numOfUruudoshi = countUruudoshi(inputYear); int howManyDays = countNumOfDays(inputYear, inputMonth, inputDay); if(inputYear == 2009){ whichDay = howManyDays % 7; }else if(inputYear < 2009){ whichDay = (howManyDays - 2009 + inputYear - numOfUruudoshi) % 7; }else if(inputYear > 2009){ whichDay = (howManyDays - 2009 + inputYear + numOfUruudoshi) % 7; } String[] dayOfWeek = {"木","金","土","日","月","火","水"}; if(whichDay < 0){ whichDay += 7; } System.out.println("あなたの入力された日付は" + dayOfWeek[whichDay] + "です。"); } static int countUruudoshi(int i_year){ int counter = 0; if(i_year <= 2009){ for(int i = 2008; i >= i_year; i--){ if((i%4 == 0 && i%100 != 0) || i%400 == 0){ counter++; } } }else{ for(int i = 2010; i <= i_year; i--){ if((i%4 == 0 && i%100 != 0) || i%400 == 0){ counter++; } } } return counter; } static int countNumOfDays(int i_year, int i_month, int i_day){ int total_day = 0; for(int i = 1; i < i_month; i++){ switch(i){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: total_day += 31; break; case 2: if((i_year%4 == 0 && i_year%100 != 0) || i_year%400 == 0){ total_day += 29; }else{ total_day += 28; } break; case 4: case 6: case 9: case 11: total_day += 30; break; } } return total_day + i_day - 1; } }