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;
                }
    }

  • 相关阅读:
    1058 A+B in Hogwarts (20)
    1046 Shortest Distance (20)
    1061 Dating (20)
    1041 Be Unique (20)
    1015 Reversible Primes (20)(20 分)
    pat 1027 Colors in Mars (20)
    PAT 1008 Elevator (20)
    操作系统 死锁
    Ajax的get方式传值 避免& 与= 号
    让IE浏览器支持CSS3表现
  • 原文地址:https://www.cnblogs.com/aland/p/3625604.html
Copyright © 2011-2022 走看看