日期:2014-05-20 浏览次数:20759 次
import java.util.*; public class CalendarTest{ public static void main(String[] args){ GregorianCalendar d = new GregorianCalendar(); int month = d.get(Calendar.MONTH); int today = d.get(Calendar.DAY_OF_MONTH); int weekday = d.get(Calendar.DAY_OF_WEEK); d.set(Calendar.DAY_OF_MONTH, 1); System.out.println("SUN MON TUE WED THU FRI SAT"); for(int i=Calendar.SUNDAY;i<weekday;i++){ System.out.print(" "); //3个空格 } do{ int day = d.get(Calendar.DAY_OF_MONTH); System.out.printf("%3d",day); if(day==today){ System.out.print("*"); } else System.out.print(" "); if(weekday==Calendar.SATURDAY){ System.out.println(); } d.add(Calendar.DAY_OF_MONTH, 1); weekday = d.get(Calendar.DAY_OF_WEEK); }while(d.get(Calendar.MONTH)==month); if(weekday != Calendar.SUNDAY){ System.out.println(); } //这个if语句的作用是? } }