标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter year: (e.g., 2008): "); 10 int year = input.nextInt(); 11 System.out.print("Enter month: 1-12: "); 12 int month = input.nextInt(); 13 System.out.print("Enter the day of the month: 1-31: "); 14 int day = input.nextInt(); 15 16 if(month == 1 || month == 2) 17 { 18 month += 12; 19 year--; 20 } 21 22 int k = year % 100; 23 int j = (int)(year / 100); 24 int weekday = (day + (int)(26 * (month + 1) / 10) + k + (int)(k / 4) + (int)(j / 4) + 5 * j) % 7; 25 26 String weekdayString = ""; 27 switch(weekday) 28 { 29 case 0: weekdayString = "Saturday"; break; 30 case 1: weekdayString = "Sunday"; break; 31 case 2: weekdayString = "Monday"; break; 32 case 3: weekdayString = "Tuesday"; break; 33 case 4: weekdayString = "Wednesday"; break; 34 case 5: weekdayString = "Thursday"; break; 35 case 6: weekdayString = "Friday"; break; 36 } 37 38 System.out.println("Day of the week is " + weekdayString); 39 } 40 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5766089.html