// 開始列印簡單的萬年曆 import java.io.*; public class a12 { public static void main(String args[]) throws Exception { //程式進入點 String getbr; BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int year;//存放西元年 int last_year;//存放去年 int days;//去年的天數 int month,day; int space,i,weekpt; int[] month_day={31,28,31,30,31,30,31,31,30,31,30,31}; //月份的天數 String[] weekname = {"日","一","二","三","四","五","六"}; String[] monthname = {"一月","二月","三月","四月","五月","六月","七月", "八月","九月","十月","十一月","十二月"}; System.out.print("請輸入西元年(大於0的正整數):"); getbr = br.readLine(); year=Integer.parseInt(getbr);//取得西元年 // 判斷該年是否為閏年 if (year%400==0) //閏年 month_day[1]=29; else if (year%100==0)//平年 month_day[1]=28; else if (year%4==0)//閏年 month_day[1]=29; else//平年 month_day[1]=28; last_year=year-1; days=last_year*365+last_year/4-last_year/100+last_year/400; //西元元年1月1日是週一 System.out.println("西元元年到去年為止總共有"+days+"天"+(days%7)); for (month=1;month<=12;month=month+1) { day=1; System.out.println(" "+monthname[month-1]); System.out.println("日 一 二 三 四 五 六"); space=(days+1)%7; for (i=1;i<=space;i=i+1) System.out.print(" "); weekpt=space-1; for (i=1;i<=month_day[month-1];i=i+1) { if (weekpt==6) { weekpt=0; System.out.println(); } else weekpt=weekpt+1; if (i<10) System.out.print(i+" "); else System.out.print(i+" "); } days=days+month_day[month-1]; System.out.println(); } } }