+ 2
need solution
4 Réponses
+ 1
In line 7, it's month == 2, not month = 2. Also you may have to initialize the season to empty string:
String season = "";
+ 1
cannot understand. please explain!
+ 1
you can add the re-edited code here. I think it will helpful for me
+ 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 + ".");
}
}