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:\x0

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/09 04:08:15
java新人求解决

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:\x0
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新人求解决"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:\x0
变量season没有被初始化,将
String season;
改为
String season=null;

String season="";
就可以了.