import java.util.Scanner;
public class Test4 {
public static void main(String[] args) {
// y是年,m是月
Scanner sc = new Scanner(System.in);
System.out.println("input a year:");
int y = sc.nextInt();
System.out.println("input a month:");
int m = sc.nextInt();
// 1、计算 1900到(y-1)年的总天数
int daysOfYear = 0;
for(int i=1900;i<y;i++){
if(i%400==0||i%4==0&&i%100!=0){
daysOfYear+=366;
}else{
daysOfYear+=365;
}
}
System.out.println("关于年的总天数:"+daysOfYear);
//2、计算 1到(m-1)月的总天数
int daysOfMonth = 0;
for(int i=1;i<m;i++){
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
daysOfMonth+=31;
}else if(i==4||i==6||i==9||i==11){
daysOfMonth+=30;
}else{//2月只由开始输入的y决定
if(y%400==0||y%4==0&&y%100!=0){
daysOfMonth+=29;
}else{
daysOfMonth+=28;
}
}
}
System.out.println("关于月的总天数:"+daysOfMonth);
//3、m-1这个月的最后一天是周几
int week = (daysOfYear+daysOfMonth)%7;
//4、m月的第一天是周几,也正好是1号前面的空格数
int spaces = week+1;
//特殊情况处理(week是6,前面会有7个空格,此时空格数应该为0)
if(week==6){
spaces = 0;
}
//5、计算m月有几天
int days = 0;
switch(m){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:days = 31;break;
case 4:
case 6:
case 9:
case 11:days = 30;break;
case 2: if(y%400==0||y%4==0&&y%100!=0){
days = 29;
}else{
days = 28;
}
break;
}
//6、打印日历
System.out.println("日\t一\t二\t三\t四\t五\t六");
int count = 0;
for(int i=1;i<=spaces;i++){
System.out.print("\t");
count++;
}
for(int i=1;i<=days;i++){
System.out.print(i+"\t");
count++;
if(count%7==0){
System.out.println();
}
}
}
}