class CalendarList{
int year,month;
int dayNum,i,num,count=0;
Calendar objCalendar;
int[] arrDayNum=;
CalendarList(){
objCalendar=Calendar.getInstance();
this.year=objCalendar.get(Calendar.YEAR);
this.month=objCalendar.get(Calendar.MONTH)+1; //要+1
}
CalendarList(String args0,String args1){
this.year=Integer.parseInt(args1);
this.month=Integer.parseInt(args0);
objCalendar=Calendar.getInstance();//这里没有get
objCalendar.set(Calendar.YEAR,year);//set是这样用的
objCalendar.set(Calendar.MONTH,month-1);
}
void display(){
System.out.println("\t\t\t"+year+"年"+month+"月");
System.out.println("日 一 二 三 四 五 六"); //每个空3个空格
num=objCalendar.get(Calendar.DAY_OF_WEEK);
if ((year/4==0&&year/100!=0)||(year/400==0)){
arrDayNum[1]+=1;
}
for (i=1;i<=12;i++){
if (i==month){
dayNum=arrDayNum[i-1];
break;
}
}
for(i=1;i<=num;i++){
System.out.print(" ");//5个空格
count++;
}
for (i=1;i<=dayNum;i++){
System.out.print(i<10?" "+i+" ":i+" "); //自己改了下 ,空格数:1,3,3
count++;
if(count==7){
System.out.println();
count=0;
}
}
System.out.println ();
}
}
public class MainClass {
public static void main(String[] args) {
CalendarList objCalendar=new CalendarList();
CalendarList objCalendar1=new CalendarList("11","2007");
objCalendar.display();
objCalendar1.display();
}
}