if(month>=3 && month<=5) {
System.out.println("spring");
}
else if(month>=6 && month<=8) {
System.out.println("summer");
}
else if(month >=9 && month <=11) {
System.out.println("autumn");
}
else {
System.out.println("winter");
}
How did this ugly Code pass ? .. output is incorrect ...... How do I fix it for Winter ?
Under discussion
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Newerwinter
15 August 2019, 18:18
Here is the best to use switch statement :)
0
Valijon
18 July 2019, 16:48
if(month==12){
System.out.println("winter");
}else if(month>=1 && month<=2){
System.out.println("winter");
}else if(month>=3 && month<=5){
System.out.println("spring");
}else if(month>=6 && month<=8){
System.out.println("summer");
}else if(month>=9 && month<=11){
System.out.println("autumn");
}
+1
Thomas
25 May 2019, 04:15
... thanks to stackoverflow for some cool java || or grammar choices
https://stackoverflow.com/questions/29855905/and-and-or-statements-in-java
..... your compiler just took a beating trying all these variations
0
Thomas
25 May 2019, 03:51
OK --- so this compiles correctly today !? ... after talking to it nicely ? But -- as Thomas C points out; my code is bogus ! lol I will be back when I figure out better grammar for a 12 or 1 or 2 statement. ![]()

0
ThomasLC
24 May 2019, 08:53
You shouldn't do that as if the user enters a number like 13 or 14 it'll still display winter
Think about how to set your last if else statement to only check for 12, 1 and 2
+2
Thomas
25 May 2019, 03:44
Good point ! my OR statement isn't happy yet ;
0