import java.util.*;
public class Calendar {
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 days = 0;
int sum = 0;
//int temp = 0;
for(int i = 1950; i<year;i++) {
if(i%4 == 0 && i%100 != 0|| i%400 == 0) {
sum += 366;
}else {
sum += 365;
}
//temp = i;
}
//System.out.println(temp);
//System.out.println(sum);
for(int i = 1;i<month;i++) {
if(i==2) {
if((year%4 == 0 && year%100 != 0)|| year%400 == 0) {
sum += 29;
}else {
sum += 28;
}
}else if(i==4||i==6||i==9||i==11) {
sum += 30;
}else {
sum += 31;
}
}
if(month==2) {
if((year%4 == 0 && year%100 != 0)|| year%400 == 0) {
days = 29;
}else {
days = 28;
}
}else if(month==4||month==6||month==9||month==11) {
days= 30;
}else {
days = 31;
}
int week = sum%7;
int arr[] = new int[42];
//System.out.println(days);
System.out.println("---------------------"+year+"年"+month+"月"+"---------------------");
System.out.println("日\t一\t二\t三\t四\t五\t六\t");
//System.out.println(sum);
//System.out.println(week);
int day = 1;
for(int i = 0;i<arr.length;i++) {
if(i <= week || i>days+week) {
arr[i] = 0;
}else {
arr[i] = day;
day++;
//System.out.println(day);
}
}
for(int i = 0;i<arr.length;i++) {
//System.out.print(arr[i]);
if(arr[i] == 0) {
System.out.print(" "+"\t");
}else {
System.out.print(arr[i]+"\t");
}
if(i%7 == 0) {
System.out.println();
}
}
}
} |