题目:编写一个输出如下图的日历程序.
     2008年1月
 日  一  二  三  四  五  六
         1   2  3   4  5
 6   7   8  9  10 11 12
 13 14  15 16  17 18 19 
 20 21  22 23  24 25 26 
 27 28  29 30  31 

解决方案 »

  1.   

    之前写的一个.忘了是在哪个帖子里了.
    static void getCalendar(){
    int year=2004;
    int month=10;
    Calendar c = GregorianCalendar.getInstance();
    c.set(Calendar.YEAR, year);//2004年
    c.set(Calendar.MONTH, month-1);//10月
    c.set(Calendar.DAY_OF_MONTH, 1);//1日
    System.out.println(c.get(Calendar.YEAR)+"年"+(c.get(Calendar.MONTH)+1)+"月");
    System.out.println("日 一 二 三 四 五 六");
    int[][] day = new int[6][7];

    while(c.get(Calendar.MONTH)+1==month){
    int i=c.get(Calendar.WEEK_OF_MONTH)-1;
    int j=c.get(Calendar.DAY_OF_WEEK)-1;
    day[i][j] = c.get(Calendar.DAY_OF_MONTH);
    c.add(Calendar.DATE, 1);
    }
    for(int i=0;i<6;i++){
    for(int j=0;j<7;j++){
    String out = day[i][j]+"";
    if(out.equals("0"))out=" ";
    if(out.length()==1)out=" "+out;
    System.out.print(out+" ");
    } System.out.println();
    }
    }
      

  2.   

    呵呵,这个程序在Core Java上卷中好像有的。