• 万年历


     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("日	一	二	三	四	五	六");
    70         int mday = countyear%7+1;
    71         
    72         for(int i =1; i<=mday; i++) {
    73             System.out.print("	");
    74         }
    75         
    76         for (int i = 1; i <= nowday; i++) {
    77             System.out.print(i+"	");
    78             if((mday + i) % 7 == 0){
    79                 System.out.println();
    80             }
    81         }
    82     }
    83 
    84 }
  • 相关阅读:
    Sentinel实现熔断和限流
    Nacos 服务注册和配置中心
    SpringCloud Sleuth 分布式请求链路跟踪
    SpringCloud Stream消息驱动
    SpringCloud Bus消息总线
    SpringCloud Config分布式配置中心
    Geteway服务网关
    Hystrix断路器
    libecc:一个可移植的椭圆曲线密码学库
    第四十二个知识点:看看你的C代码为蒙哥马利乘法,你能确定它可能在哪里泄漏侧信道路吗?
  • 原文地址:https://www.cnblogs.com/jliu-l/p/13279966.html
Copyright © 2020-2023  润新知