6 回答
TA贡献2条经验 获得超2个赞

package hello;
public class HelloWorld{
public static void main(String[] args){
String today="周末";
String weather="晴朗";
if (today.equals("周末")){
if (weather.equals("晴朗")){
System.out.println("去室外游乐场游玩");
}
else {
System.out.println("去室内游乐场游玩");
}
}
else{
System.out.println("去上班");
}
}
}问题出在你在最后一个else语句放在了第一个if{}语句块里面,我改了一下,你看看
TA贡献7条经验 获得超9个赞
public class HelloWorld{
public static void main(String[] args){
String today="周末";
String weather="晴朗";
if (today.equals("周末")){
if (weather.erquals("晴朗")){
System.out.println("去室外游乐场游玩");
}else{
System.out.println("去室内游乐场游玩");
}
}else{
System.out.println("去上班");
}
}
}
TA贡献47条经验 获得超30个赞
else{
System.out.println("去室内游乐场游玩");
}
改为
else if{
System.out.println("去室内游乐场游玩");
}
只有最后一个分支才可以试用else
添加回答
举报
