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

万年历

时间:2020-07-10 16:49:45      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:tin   auth   ==   ati   default   万年历   print   public   int()   

 1 /**
 2  * @author jliu.l
 3  * @2020年7月7日
 4  * 
 5  */
 6 public class Calendar {
 7 
 8     public static void main(String[] args) {
 9         System.out.println("================万年历===============");
10         Scanner sc = new Scanner(System.in);
11         System.out.print("请输入年份:");
12         int year = sc.nextInt();
13         System.out.print("请输入月份:");
14         int month = sc.nextInt();
15         int countyear = 0;//1900到此年份的天数
16         
17         for(int i=1900;i<year;i++) {
18             //闰年:能被4整除,但是不能被100整除,或者能被400整除的数
19             if((year%4==0 && year%100!=0) || (year%400==0)) {
20                 countyear += 366;
21             }else {
22                 countyear += 365;
23             }
24         }
25         //输入的月的前面的月的天数
26         for(int i=1;i<month;i++) {
27             switch (i) {
28             case 1:
29             case 3:
30             case 5:
31             case 7:
32             case 8:
33             case 10:
34             case 12: 
35                 countyear += 31;
36                 break;
37             case 2:
38                 if((year%4==0 && year%100!=0) || (year%400==0)) {
39                     countyear += 29;
40                 }else {
41                     countyear +=28;
42                 }
43                 break;
44             case 4:
45             case 6:
46             case 9:
47             case 11:
48                 countyear +=30;
49                 break;
50             default :
51                 break;
52             }
53         }
54         
55         int nowday = 0;
56         if(month == 2) {
57             if((year%4==0 && year%100!=0) || (year%400==0)) {
58                 nowday = 29;
59             }else {
60                 nowday = 28;
61             }
62         }else if (month == 4 || month == 6 ||month == 9 ||month == 11) {
63             nowday = 30;
64         }else {
65             nowday = 31;
66         }
67         System.out.println(countyear);
68         System.out.println(nowday);
69         System.out.println("日\t一\t二\t三\t四\t五\t六");
70         int mday = countyear%7+1;
71         
72         for(int i =1; i<=mday; i++) {
73             System.out.print("\t");
74         }
75         
76         for (int i = 1; i <= nowday; i++) {
77             System.out.print(i+"\t");
78             if((mday + i) % 7 == 0){
79                 System.out.println();
80             }
81         }
82     }
83 
84 }

 

万年历

标签:tin   auth   ==   ati   default   万年历   print   public   int()   

原文地址:https://www.cnblogs.com/jliu-l/p/13279966.html

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