作业帮 > 综合 > 作业

java新人求解决"variable season might not have been initialized"

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/12 07:03:38
java新人求解决"variable season might not have been initialized"
public class Ifscore{
\x05public static void main(String args[]){
\x05\x05int month = 7;
\x05\x05String season;
\x05\x05switch (month){
\x05\x05 case 3:
\x05\x05 case 4:
\x05\x05 case 5:
\x05\x05 season = "Spring";
\x05\x05\x05break;
\x05\x05 case 6:
\x05 case 7:
\x05\x05 case 8:
\x05\x05\x05season = "Summer";
\x05\x05\x05break;
\x05\x05 case 9:
\x05\x05 case 10:
\x05 case 11:
\x05\x05\x05season = "Autumn";
\x05\x05\x05break;
\x05\x05 case 12:
\x05\x05 case 1:
\x05\x05 case 2:
\x05\x05\x05break;
\x05\x05default:
\x05\x05 season = "Bogus Month";
\x05\x05}
\x05\x05System.out.println("July is in the " + season+".");
\x05}
}
java新人求解决
变量season没有被初始化,将
String season;
改为
String season=null;

String season="";
就可以了.