public class MoonShow {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
System.out.println("输入年份:");
int year = input.nextInt();
System.out.println("输入月份:");
int month = input.nextInt();
//2,计算输入年份的1月1号距离1800年的1月1号的总天数。
public static int totalday(int year){
int totalday = 0;
for(int x = 1800; x < year; x++){
if(x % 400 == 0 || (x % 4 == 0 && x % 100 != 0))
totalday +=366;
else
totalday +=365;
}
return totalday;
}
//3,计算月份的天数。
public static int monthDays(int month,int year){
int sum = 0;
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
sum = 31;
break;
case 4: case 6: case 9: case 11:
sum = 30;
break;
case 2:
if(year % 400 == 0 || (year % 4 == 0 && year% 100 != 0))
sum = 29;
else
sum = 28;
break;
}
return sum;
}
//4,计算输入年份一月一号是星期几。
public static int weekday(int month, int year){
int sum = 0;
for(int a = 1; a< month;a++){
sum += monthDays(a,year);
}
int totalday = sum + totalday( year);
int weekday = (totalday + 3) % 7;
return weekday;
}