java程序——输出当月日历表

import java.util.Calendar;
public class Calendar0 {
  public static void main(String[]args){
    Calendar cal = Calendar.getInstance();
    int year=cal.get(Calendar.YEAR);//目前是哪一年
    int month=cal.get(Calendar.MONTH);//目前是哪一月
    int day=cal.get(Calendar.DAY_OF_MONTH);//今天是哪天
    int week=cal.get(Calendar.DAY_OF_WEEK)-1;//今天星期几,周一是1,周日是0
    int week0=(week-day%7+1)%7;//这个月的一号是星期几
    int[] Month={31,28,31,30,31,30,31,31,30,31,30,31};//一年当中的每个月的数目
    int count=0;
    System.out.println(year+"年"+(month+1)+"月"+day+"日");

    System.out.println("Sun\t"+"Mon\t"+"Tue\t"+"Wed\t"+"Thu\t"+"Fri\t"+"Sat\t");
    while(week0!=0){
      System.out.print("\t");
      week0--;count++;
    }
    if((year%400==0)||(year%4==0&&year%100!=0))
    Month[1]=29;
    for(int i=0;i<Month[month];i++){
      System.out.print((i+1)+"\t");
      count++;
    if(count%7==0)
    System.out.println();
    }
  }
}

posted @ 2016-09-16 23:36  天下岂有长生不灭者  阅读(1704)  评论(0编辑  收藏  举报