• 万年历


    package pro2;
    import java.util.Scanner;
    public class Year01 {
      public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.print("请输入要打印的年月(格式如201709)");
        int flag=sc.nextInt();
        test(flag);
      }
      public static int year(int year){
        if((year%400==0)||(year%4==0&&year%100!=0)){
          return 1;
        }
        else
          return 0;
      }
      public static int month(int year,int month){
        int one[]={1,3,5,7,8,10,12,-1,-1,-1,-1,-1};
        int two[]={4,6,9,11,-1,-1,-1,-1,-1,-1,-1,-1};
        for(int i=0;i<12;i++){
          if(month==one[i]){
            return 31;
          }
          else if(month==two[i]){
            return 30;
          }
          else if(month==2){
            int key=year(year);
            if(key==1){
              return 29;
            }
            else if(key==0){
              return 28;
            }
          }
        }
        return 0;
      }
      public static int judgeDay(int year,int month){
        int Ycount=0;
        int Mcount=0;
        {//此代码段判断某年前一共差多少天
          for(int i=1900;i<year;i++){
            int key1=year(i);
            if(key1==1){
              Ycount+=366;
            }else if(key1==0){
              Ycount+=365;
            }
           }
        }{//此代码段判断 某月前一共多少天
          for(int i=1;i<month;i++){
            int key2=month(year,i);
            Mcount+=key2;
          }
        }
        return (Ycount+Mcount);
      }
      public static void printMonth(int year,int month){
        int key=judgeDay(year,month);
        int week=(key+1)%7;
        System.out.println("Sun Mon Tue Wed Thu Fri Sat");
        for(int i=0;i<week;i++){
          System.out.printf(" ");
        }
        for(int i=0;i<month(year,month);i++){
          System.out.printf(" %-3d",i+1);
          if((week+i)%7==6){
            System.out.print(" ");
          }
        }
      }
      public static void test(int num){
        int year=num/100;
        int month=num%100;
        printMonth(year,month);
      }

    }

  • 相关阅读:
    CVE-2021-25646 Apache Druid远程命令执行漏洞复现
    CVE-2021-3156漏洞复现
    助力抗疫 Splashtop 远程控制软件限时免费
    Splashtop Business Access 的常见问题解答
    热烈祝贺 Splashtop 荣获“最佳远程办公解决方案”奖
    Mark Lee:Splashtop 如何成为最新的 10 亿美元估值技术独角兽
    Splashtop获5000万美元新投资 成为远程桌面行业独角兽
    热烈祝贺 Splashtop 赢得最佳远程桌面用户满意度得分
    [翻译系列]正则表达式简介
    tensorflow2.0 keras 迁移学习 删除预训练模型的最后一层(layer)
  • 原文地址:https://www.cnblogs.com/hxtblogs/p/7591325.html
Copyright © 2020-2023  润新知