好的,我检查了您的图像(我通常不这样做)并在您的代码中发现了几个问题。
public static String getWeatherAdvice(int temperature, String description)
{
{ // REMOVE THIS BRACKET
if ( Windy = true) // = signifies an assigning a value, not a comparison. Use ==
return "It is Windy";
else
return "Not Windy";
if ( temperature < 30 ); // Since the above if-else will always return a value, this
// code can not be reached. Put this if before the previous if-else. Also: remove the ; after the if statement, otherwise, it ends the if, and the return statement might be triggered.
{ // don't put this bracket if you have a ; after the if
return "Too windy ... ";
} // don't put this bracket if you have a ; after the if
} // REMOVE THIS BRACKET
}
您的代码的更正版本(可能是):
public static String getWeatherAdvice(int temperature, String description)
{
if ( temperature < 30 )
{
return "Too windy ... ";
}
if ( Windy == true) // can also be written as: if ( Windy )
return "It is Windy";
else
return "Not Windy";
}