import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
public class NianLi {
public static void main(String[]args) throws IOException{
//缓冲输入流
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入日期,如yyyy");
String rq=br.readLine();
br.close();
int d=Integer.parseInt(rq);
for(int m=0;m<=11;m++){
Calendar c=Calendar.getInstance();
c.set(Calendar.YEAR, d);
c.set(Calendar.MONTH,m);
//当前日期中当前月对应的最大天数
int allDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
//当前日期中当前月第一天对应的星期数
c.set(Calendar.DAY_OF_MONTH, 1);
int firstDay = c.get(Calendar.DAY_OF_WEEK);
System.out.println(" 第"+(m+1)+"月的月历");
System.out.println("日 一 二 三 四 五 六");
c.set(Calendar.MONTH,m);
for (int j = 1; j < firstDay; j++) {
System.out.print(" ");
}
for (int i = 1; i <= allDay; i++) {
System.out.print(i + " ");
//每到星期六就换行
c.set(Calendar.DATE, i);
if (c.get(Calendar.DAY_OF_WEEK) % 7 == 0) {
System.out.println("
");
}
}
System.out.println("
");
}
}
}