Java:万年历打印输出

来源:互联网 发布:手机棋牌游戏平台源码 编辑:程序博客网 时间:2024/06/08 11:26
public static void main(String[] args) {
            {
                System.out.println("*请输入年份*");
                int[] c=new int[3];
                int[][] month={{31,28,31},{30,31,30},{31,31,30},{31,30,31}};
                int[][] index={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
                Scanner scan=new Scanner(System.in);
                int year=scan.nextInt();
                int s=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+1);
                int w=s%7;
                if((year%100==0&&year%400==0)||(year%100!=0&&year%4==0))
                {
                    month[0][1]+=1;
                }

                for(int q=0;q<4;q++)
                {
                    for(int i=0;i<=2;i++)
                    {
                        System.out.print(index[q][i]+"月\t\t\t\t\t\t\t");
                    }
                    System.out.println();
                    for(int i=0;i<=2;i++)
                    {
                        System.out.print("日\t"+"一\t"+"二\t"+"三\t"+
                                "四\t"+"五\t"+"六\t");
                    }
                    System.out.println();
                    for(int i=0;i<=2;i++)
                    {
                        int a=1;
                        for(int j=0;j<w;j++)
                        {
                            System.out.print(" \t");
                        }
                        while(w<7)
                        {
                            System.out.print(a+"\t");
                            a++;
                            w++;
                        }
                        s+=month[q][i];
                        w=s%7;
                        c[i]=a;
                    }
                    for(int k=0;k<5;k++)
                    {
                        System.out.println();
                        for(int i=0;i<3;i++)
                        {
                            for(int j=0;j<7;j++)
                            {
                                if(c[i]<=month[q][i])
                                {
                                    System.out.print(c[i]+"\t");
                                    c[i]+=1;
                                }
                                else
                                    System.out.print("\t");        
                            }
                        }
                    }
                    System.out.println();
                }
            }
        }
0 0