所以我在編程類的介紹中被分配了一個問題。我做了一點研究,以完成這個問題,我能夠編譯沒有錯誤,但其中一個規定是我必須返回一個字符串。這是我把頭撞到一堵磚牆的地方。我嘗試了一些方法來解決這個問題,但我希望這裏有人能夠發現我一直在拉我的頭髮的問題。程序不會返回字符串
public class TellSeason {
public static void main(String[] args) {
season(5 , 12);
}
public static String season(int month , int day) {
if ((month == 9 && day >=16)
|| month == 10
|| month == 11
|| (month == 12 && day <=15)) {
return ("Fall");
}
else if ((month == 12 && day >=16)
|| month == 1
|| month == 2
||(month == 3 && day <=15)) {
return ("Winter");
}
else if ((month == 3 && day >=16)
|| month == 4
|| month == 5
||(month == 6 && day <=15)) {
return ("Spring");
}
else {
return("Summer");
}
}
}
的'是什麼|'的對?這不是爲我重申。 –
程序的返回值總是int。你確定這個需求不僅僅是把一個字符串打印到標準輸出嗎? – Mureinik
||是'或'操作數。但是我能夠完成這個問題 – UpTooLate