我問過你關於GregorianCalendar
和Calendar
有人說Calendar
比較好。所以我做了Calender
班。兩個問題
我有一個方法的問題:JavaApplication1#whichIsEarlier(),
總是收到錯誤。請檢查它,如果可以的話。如何解決它?我會感謝你的幫助。
public class JavaApplication1 {
public static void main(String[] args) {
Calendar yy =Calendar.getInstance();
Calendar xx= Calendar.getInstance();
xx.set(2001, 10,10);
Data dt = new Data(yy);
Data xt = new Data(xx);
Data dd = new Data(yy, xx);
System.out.println(dt.toString());
System.out.println(xt.toString());
System.out.println(dd.whichIsEarlier());
}
}
class Data {
private Calendar calendar;
Calendar cale;
Data(Calendar x){
calendar = x;
}
Data(Calendar x, Calendar y){
calendar = x;
cale = y;
}
public String toString(){
String months[] = {"Jan","Feb", "Mar" , "Apr", "Mai", "June", "July","Aug",
"Sep", "Okt", "Nov", "Dec"};
String str = "";
str = "Data: "+ calendar.get(Calendar.DATE) +" "+ months[calendar.get(Calendar.MONTH)]+
" "+ calendar.get(Calendar.YEAR);
return str;
}
public String whichIsEarlier(Calendar cale){
String str = "";
if(calendar.after(cale)) str = calendar.toString() ;
else str = cale.toString();
return str +" jest wczesniej";
}
}
首先檢查方法'whichIsEarlier'的簽名,然後看看你是否正確調用呢? –
什麼是錯誤信息? – hexafraction
「有人說''日曆'比較好」 - 好吧'GregorianCalendar'只是'Calendar'的一個子類。這不是一個「更好」的問題 - 這是根據上下文選擇使用哪一個的問題。 –