import java.util.Scanner;
public class perpetualCalendar {
public static void main(String[] args) {
// TODO Auto-generated method stub
int year;//年
int month;//月
int day=0;//天數
boolean ren;//是閏年為true,不是為false
int totalDays=0;//1900年到現在的總天數
System.out.println("*****************萬年曆*****************");
Scanner input = new Scanner(System.in);
System.out.println("請輸入年:");
year = input.nextInt();
System.out.println("請輸入月:");
month = input.nextInt();
if((year%400==0)||(year%4==0&&year%100!=0)) {
ren = true; }
else { ren = false;
}
//計算1900年到今年的總天數
for(int i = 1900;i<year;i++) {
if(ren) {
totalDays = totalDays+366;
}else {
totalDays = totalDays+365;
}
}
for(int i = 1;i<=month;i++) {
switch(i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 4:
case 6:
case 9:
case 11:
day=30;
break;
case 2:
if(ren) {
day = 29;
}
else{
day = 28;
}
break;
default:
System.out.println("月份輸入有誤");
}
//為了使day的值等於查詢月份的天數,並不會加到總天數裡
if(i!=month) {
totalDays = totalDays+day;//總年數的天數加上查詢月份之前月份的天數
}
}
//求星期幾,就是前面\t的個數
int beforDays;
beforDays = 1 + totalDays%7;
if(beforDays == 7) {
beforDays = 0;//代表星期天,0個\t
}
System.out.println("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
//先列印\t
for(int i=0;i<beforDays;i++) {
System.out.print("\t");
}
for(int i=1;i<=day;i++) {
System.out.print(i+"\t");
//滿七個換行
if((i+beforDays)%7==0) {
System.out.println();
}
}
//System.out.println(month+"月有"+day+"天");
}
}