import java.util.*;
class WNL {
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
System.out.println("输入年份");
int year = sc.nextInt();
System.out.println("输入月份");
int month = sc.nextInt();
int sum = getSum(year ,month);
print((sum+1)%7,month,year);
}
public static int getSum(int year , int month ){
int sum = 0;
for(int i = 1900 ; i < year; i++){
//判断 平年 润年;
if((i % 400 == 0) || ( (i % 4 == 0) && (i %100 != 0) )){
sum += 366;// 闰年 :1 能被 400 整除 . 2:能被 4 整除 并且 不能被 100 整除
}else{
sum += 365 ;// 平年
}
}
System.out.println(sum);
// 求出 月份的 天数;
switch (month-1){
case 12:
sum += 31;
case 11:
sum += 30;
case 10:
sum += 31;
case 9:
sum += 30;
case 8:
sum += 31;
case 7:
sum += 31;
case 6:
sum += 30;
case 5:
sum += 31;
case 4:
sum += 30;
case 3:
sum += 31;
case 2:
// 判断;
if((year % 400 == 0) || ( (year % 4 == 0) && (year %100 != 0) )){
sum += 29;
}else{
sum += 28;
}
case 1:
sum += 31;// 365 + 31 + 28
}
System.out.println(sum);
return sum ;
}
public static void print(int space,int month, int year){
int day = 0;
switch (month){
case 2:
if((year % 400 == 0) || ( (year % 4 == 0) && (year %100 != 0) )){
day = 29;
}else{
day = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
day=30;
break;
default:
day = 31;
}
System.out.println("日\t一\t二\t三\t四\t五\t六");
// 打印 前面的空格;
/*
for(int i = 1 ;i <= space ; i++ ){
System.out.print("\t");
}
// 打印 日子;
for(int i =1 ; i <= day ; i++){
if((space+i) % 7 == 0){
// 换行;
System.out.println(i+"\t");
}else{
System.out.print(i+"\t");
}
}
*/
for(int i = 1; i <= (space +day);i++){
if(i<=space){
System.out.print("\t");
}else{
if(i % 7 ==0){
System.out.println((i-space)+ "\t");
}else{
System.out.print((i-space)+"\t");
}
}
}
}
}
|