码迷,mamicode.com
首页 > 其他好文 > 详细

HW5.34

时间:2016-08-23 14:45:34      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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         System.out.print("Enter the year: ");
 9         int year = input.nextInt();
10         input.close();
11 
12         for(int i = 1; i <= 12; i++)
13             System.out.println(year + "-" + getMonth(i) + "-" + "1 is " + getWeekday(year, i, 1));
14     }
15 
16     public static String getMonth(int monthValue)
17     {
18         String monthStr = "";
19 
20         switch(monthValue)
21         {
22             case 1: monthStr = "January"; break;
23             case 2: monthStr = "February"; break;
24             case 3: monthStr = "March"; break;
25             case 4: monthStr = "April"; break;
26             case 5: monthStr = "May"; break;
27             case 6: monthStr = "June"; break;
28             case 7: monthStr = "July"; break;
29             case 8: monthStr = "August"; break;
30             case 9: monthStr = "Sepetember"; break;
31             case 10: monthStr = "October"; break;
32             case 11: monthStr = "November"; break;
33             case 12: monthStr = "December"; break;
34         }
35 
36         return monthStr;
37     }
38 
39     public static String getWeekday(int year, int month, int day)
40     {
41         if(month == 1)
42         {
43             month = 13;
44             year--;
45         }
46 
47         if(month == 2)
48         {
49             month = 14;
50             year--;
51         }
52 
53         int week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7;
54         String weekStr = "";
55 
56         switch(week)
57         {
58             case 0: weekStr = "Monday"; break;
59             case 1: weekStr = "Tuesday"; break;
60             case 2: weekStr = "Wednesday"; break;
61             case 3: weekStr = "Thursday"; break;
62             case 4: weekStr = "Friday"; break;
63             case 5: weekStr = "Saturday"; break;
64             case 6: weekStr = "Sunday"; break;
65         }
66         return weekStr;
67     }
68 }

 

HW5.34

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5798975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!