java程序为什么加了try,catch后 System.out.println(。。。)不...
发布网友
发布时间:2024-04-21 15:48
我来回答
共1个回答
热心网友
时间:2024-04-21 23:18
//帮你改了一下,测试通过了~不会再问
package Test;
class Date {
public String year;
public String month;
public int day;
Date(String year, String month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public static void main(String args[]) {
Date[] days = new Date[7];
try {
for (int i = 0; i < 7; i++) {
days[i] = new Date("2009", "7", i+1);
System.out.println(days[i].getYear() + "年" + days[i].getMonth()
+ "月" + days[i].getDay() + "日");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}