package skt;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class skt{
public static void main (String[] args) {
ArrayList<String> two =new ArrayList<String>();
System.out.print("请输入年份:");
Scanner year =new Scanner(System.in);
int a=year.nextInt();
if(a<=1900&&a>=2100){
System.out.print("输入错误重新输入");
}
System.out.print("请输入月份:");
Scanner month =new Scanner(System.in);
int e=month.nextInt();
if(e<1&&e>12){
System.out.print("输入错误请从新输入");
}
//获得了月份之后开始计算日历前的空格,因为已知空格数等于
//月份1日的星期减一为空格数。要知道已知从1900年开始每过
//7天后为星期一,要得到空白数公式为总天数%7+1
int yearDays=0;
int januaryDays=0;
for(int i=1900;i<a;i++){
if(i%4==0&&i%100!=0||i%400==0){
yearDays+=366;
}
else{
yearDays+=365;
}
}
//现在开始计算月份的总天数了
for(int j=1;j<e;j++){
if(j==2){
if(a%4==0&&a%100!=0||a%400==0){
januaryDays+=29;
}
else{
januaryDays+=28;
}
}
else if(j<=7&&j%2!=0||j>7&&j%2==0){
januaryDays+=31;
}
else
januaryDays+=30;
{
}
}
int space=januaryDays+yearDays;
int week=space%7+1;//得到了星期几
int blank=week;//得到了空白的数量
for(int x=0;x<=blank;x++){
two.add(" ");
}
int daysr=0;
if(e==2){
if(a%4==0&&a%100!=0||a%400==0){
daysr+=29;
}
else{
daysr+=28;
}
}
else if(e<=7&&e%2!=0||e>7&&e%2==0){
daysr+=31;
}
else
daysr+=30;
{
}
for(int u=1;u<daysr;u++){
two.add(""+u);
}
System.out.println("**************************************************");
System.out.println("一\t二\t三\t四\t五\t六\t日");
for(int z=1;z<(daysr+blank);z++){
if(z%7==0){
System.out.println();
}
System.out.print(two.get(z)+‘\t‘); }
System.out.print("");
System.out.println();
System.out.println("***************************************************");
}}