import java.util.Calendar;
import java.util.GregorianCalendar;
public class CalTest {
public static void main(String[] argv) {
CalTest calTest = new CalTest();
calTest.cal(2009, 11);
}
public void cal(final int year, final int month) {
Calendar calendar = new GregorianCalendar();
calendar.set(year, month-1, 1);
int week = calendar.get(GregorianCalendar.DAY_OF_WEEK) - 1;
int days = calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
System.out.println();
System.out.println("日\t一\t二\t三\t四\t五\t六");
for(int i = 0; i < week; i++) {
System.out.println("\t");
}
for(int i = 1; i <= days; i ++) {
System.out.print(i + "\t");
if((week + i)%7 == 0) {
System.out.println();
}
}
}
}
运行效果:
凡是有该标志的文章,都是该blog博主Caoer(草儿)原创,凡是索引、收藏
、转载请注明来处和原文作者。非常感谢。