Java:萬年曆列印輸出
阿新 • • 發佈:2018-12-25
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();
}
}
}
{
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();
}
}
}