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("去上班"); } } }D:\liujiahao\zuoye>javac HelloWorld.javaHelloWorld.java:11: 错误: 有 'if', 但是没有 'else' } else{ ^1 个错误
2 回答
已采纳

什么什么青年欢乐多
TA贡献7条经验 获得超10个赞
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("去上班"); }

_潇潇暮雨
TA贡献646条经验 获得超225个赞
你的if else嵌套不对,仔细看看你的第一个if语句对应了2个else,还有,贴代码的时候最好使用提供的代码格式化工具,不要直接贴纯文本的,这样便于别人快速找到问题.
添加回答
举报
0/150
提交
取消