need solution | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
20th Nov 2022, 3:21 PM
Mustakim Rahman
Mustakim Rahman - avatar
4 Answers
+ 1
In line 7, it's month == 2, not month = 2. Also you may have to initialize the season to empty string: String season = "";
20th Nov 2022, 3:32 PM
Mozzy
Mozzy - avatar
+ 1
cannot understand. please explain!
20th Nov 2022, 3:38 PM
Mustakim Rahman
Mustakim Rahman - avatar
+ 1
you can add the re-edited code here. I think it will helpful for me
20th Nov 2022, 3:39 PM
Mustakim Rahman
Mustakim Rahman - avatar
+ 1
In the first if statement, you should change the =, which is an assignment operator, to ==, which is a comparison operator, since you're making a comparison with a number, not setting a value. Also in the first if statement body, you did not set a value for the string season, which will raise an error since the output uses season and expects it to have a value. Try something like this: public class program { public static void main(String args[]) { int month = 4; String season; if(month == 12 || month == 1 || month == 2) season = "Winter"; else if(month == 3 || month == 4 || month == 5) season = "Spring"; else if(month == 6 || month == 7 || month == 8) season = "Summer"; else if(month == 9 || month == 10 || month == 11) season = "Autumn"; else season ="Bogus month"; System.out.println("April is in the "+ season + "."); } }
20th Nov 2022, 4:09 PM
Mozzy
Mozzy - avatar