package ppt11util类; import java.util.Calendar; public class TprintCalendar { public static void main(String[] args) { printCalendar(2017,6); } public static void printCalendar(int year,int month){ System.out.println("日 一 二 三 四 五 六"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH,(month-1)); cal.set(Calendar.YEAR,year); //1号是周几 int what = cal.get(Calendar.DAY_OF_WEEK); for (int i = 0; i < what; i++) { System.out.print(" "); } for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) { System.out.print(i+" "); if((what+i)%7==0){ System.out.println(""); } } } }