Hi,
Does anyone have an idea why this code is not working ? Btw I also tried with && and still not working -->>>
public class Solution {
public static void main(String[] args) {
checkSeason(12);
checkSeason(4);
checkSeason(7);
checkSeason(10);
}
public static void checkSeason(int month) {
//write your code here
if (month < 3 || month > 11) {
System.out.println("winter");
}
else if (month < 6 || month > 2){
System.out.println("spring");
}
else if (month < 9 || month > 5) {
System.out.println("summer");
}
else (month < 12 || month > 8) {
System.out.println("autumn");
}
}
}
Hi,
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Michael
27 September 2019, 20:16solution
The 1st condition can never be true
. Use the following construct
Lastly, do not set a condition to the 'else' statement, because this will always create a runtime error. ;-)
+2
Kris
30 September 2019, 11:01solution
Thanks mate :)
It works now, although I made quite a mess =
1) winter should be == 12 == 1 ==2
2) spring, summer and autumn I should use && instead ||
3) autumn's else should be else if
+2