public class Demo6 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个年份");
int a = sc.nextInt();
System.out.println("请输入一个月份");
int b = sc.nextInt();
int first = getFirst(a,b);
int last = getLast(a,b);
print(first,last);
}
public static int getFirst(int y,int m){
Calendar c = Calendar.getInstance();
c.set(y, m - 1, 1);
return c.get(Calendar.DAY_OF_WEEK);
}
public static int getLast(int y,int m){
Calendar c = Calendar.getInstance();
c.set(y, m, 1);
c.add(Calendar.DAY_OF_MONTH, -1);
return c.get(Calendar.DAY_OF_MONTH);
}
public static void print(int first,int last){
System.out.println("日\t一\t二\t三\t四\t五\t六");
for (int i = 1; i < first + last ; i++) {
if (i < first) {
System.out.print("\t");
}else if (i >= first) {
System.out.print((i - first + 1)+"\t");
}
if (i % 7 == 0) {
System.out.println();
}
}
}
}