zoukankan      html  css  js  c++  java
  • 月历卡片

    //import java.util.Calendar;
    import java.util.Scanner;
    public class Main {
                public static void main(String args[]) throws Exception {
                       Scanner input = new Scanner(System.in);                     
                        int y=input.nextInt(); 
                        int m=input.nextInt(); 
                       
                        String[] ms ={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
                        System.out.println("    " + y+"年"+ms[m-1]);
                        System.out.println("日 一 二 三 四 五 六"); 
                        int days = getDaysOfMonth(y,m);                  
                        int week = getWeek(y,m);
                       
                        for(int i =0;i<week;i++)
                        {
                         StdOut.print("   "); 
                        }
                        int site=1;
                        for(int j=1;j<=7 - week;j++)
                        {
                         StdOut.printf("%2d ", j);
                         site=j;
                        }
                        System.out.println();
                       
                        for(int i=site+1;i<=days;i++)
                        {
                         StdOut.printf("%2d ", i);
                         if((i-site) %7==0)System.out.println();                     
                        }
                      }
                     
                private static int getDaysOfMonth(int year,int month)
                {
                 /*
                 Calendar cal = Calendar.getInstance();
                 cal.set(Calendar.YEAR, year); 
                 cal.set(Calendar.MONTH, month-1); 
                 int days_of_month = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
                 return days_of_month;
                 */
                 int[] months={31,28,31,30,31,30,31,31,30,31,30,31};
                 
                 if((year%4==0&&year%100!=0)||(year%400==0))
                 {
                  months[1]=29;
                 }
                 return months[month-1];
                }
               
                private static int getWeek(int year,int month)
                {
                 int a = (14-month)/12;
                 int y=year-a;
                 int m=month+12*a -2;
                 int day = 1;
                 int week=(day+y+y/4-y/100+y/400+31*m/12)%7; 
                 return week;
                }
    }

  • 相关阅读:
    Qt中实现启动画面(延时过程中要加上app.processEvents())
    Qt5中生成和使用静态库
    360云后台(使用HTTP Cache服务器)
    lucene 从2.4.0—3.6.0—4.3.1版本升级
    从C++到Qt(命令行编译,讲解原理)
    赵伟国的逻辑
    windows 7 系统进程服务详解
    QT 4.87 changes
    海量小文件存储
    最大连续子序列乘积
  • 原文地址:https://www.cnblogs.com/aland/p/3625604.html
Copyright © 2011-2022 走看看