import java.util.Scanner;
class Calender
{
static final int N=1900 ;
public static void main (String[] args)
{
int year;
int month;
int sum;
int m=0 ;
Scanner sc= new Scanner(System.in );
System.out .println("请输入需要查询的年份(>1900)" );
year=sc.nextInt();
System.out .println("请输入需要查询的月份(>12)" );
month=sc.nextInt();
sum=getAllDay(year,month);
System.out .println("一\t二\t三\t四\t五\t六\t日" );
for (int i=1 ;i<=sum%7 ;i++)
{
System.out .print(" \t" );
}
for (int i=1 ;i<=7 -sum%7 ;i++)
{
System.out .print(i+"\t" );
}
System.out .println();
for (int i=7 -sum%7 +1 ;i<=getMDay(month,year);i++)
{
System.out .print(i+"\t" );
m++;
if (m%7 ==0 )
{
System.out .println();
m=0 ;
}
}
}
public static boolean isLeap (int year)//判断闰年
{ boolean flag=false ;
if ((year%4 ==0 &&year%100 !=0 )||year%400 ==0 )
{
flag=true ;
}
return flag;
}
public static int getMDay (int month,int year)//得到某一个月的天数
{
int day;
switch (month){
case 4 :
case 6 :
case 9 :
case 11 : day=30 ;
break ;
case 2 :
if (isLeap(year))
{
day=29 ;
}else {
day=28 ;
}
break ;
default :
day=31 ;
break ;
}
return day;
}
public static int getYDay (int year)//得到某一年的天数
{ int day;
if (isLeap(year))
{
day=366 ;
}else {
day=365 ;
}
return day;
}
public static int getAllDay (int year,int month)//得到从1900 到输入的那一天之前所有的天数
{
int sum1=0 ;
int sum2=0 ;
for (int i=N;i<=year-1 ;i++)
{
sum1=sum1+getYDay(i);
}
for (int i=1 ;i<=month-1 ;i++)
{
sum2=sum2+getMDay(i,year);
}
int sum=sum1+sum2;
return sum;
}
}