package com.homework;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.Scanner;public class Q1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("请输入年月,格式如2009-09"); Scanner scanner = new Scanner(System.in); String yearMonth = scanner.nextLine(); String[] str = yearMonth.split("-"); //1.得到该月第一天的日历 Calendar c = new GregorianCalendar(Integer.parseInt(str[0]), Integer.parseInt(str[1])-1, 1) ; //2.得到该月第一天星期几 int week = c.get(Calendar.DAY_OF_WEEK); //3.这个月有多少天 int days = c.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println(week + " "+ days); System.out.println("日\t一\t二\t三\t四\t五\t六"); int d = week-1; for(int i = 0 ;i < d ;i ++){ System.out.print("\t"); } System.out.print(1+"\t"); d++; for(int i = 2; i <= days;i++){ if(d == 7 ){ d=0; System.out.println(); } System.out.print(i+"\t"); d++; } }}