麻烦帮忙看看 哪里出问题了? 是括号的问题吗

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.java

HelloWorld.java:11: 错误: 有 'if', 但是没有 'else'

        } else{

          ^

1 个错误


此生不变丶
浏览 1436回答 2
2回答

什么什么青年欢乐多

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("去上班");   }

_潇潇暮雨

你的if else嵌套不对,仔细看看你的第一个if语句对应了2个else,还有,贴代码的时候最好使用提供的代码格式化工具,不要直接贴纯文本的,这样便于别人快速找到问题.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java