为了账号安全,请及时绑定邮箱和手机立即绑定

请教大神!花括号放在 if (score>80) { 这里为什么会错?

public class HelloWorld {
    public static void main(String[] args) {
  int score = 94;
  String sex = "女"; 
  if (score>80) {
   if (sex.equals("女"))
    System.out.println("进女子组");
   } else {
    System.out.println("进男子组");
   } else {
    System.out.println("淘汰");
   }

  
    }
}

正在回答

4 回答

大括号要前后对应

你的if (sex.equals("女"))后面少了一个前括号    第二个else前面少了一个后括号

public class HelloWorld {

    public static void main(String[] args) {

        int score = 94;

        String sex = "女"; 

        if (score>80) {

            if (sex.equals("女")){

                System.out.println("进女子组");

            } 

            else {

                System.out.println("进男子组");

            } 

        }

        else {

            System.out.println("淘汰");

        }


  
    }
}

0 回复 有任何疑惑可以回复我~
public class HelloWorld {
    public static void main(String[] args) {
  int score = 94;
  String sex = "女"; 
  if (score>80) {
       if (sex.equals("女")){
            System.out.println("进女子组");
           } else {
            System.out.println("进男子组");
           }
        } else {
    System.out.println("淘汰");
   }

  
    }
}
1 回复 有任何疑惑可以回复我~

 if (sex.equals("女"))  你这里后面少了一个“{”花括号

0 回复 有任何疑惑可以回复我~

if (score>80) {
   if (sex.equals("女"))
    System.out.println("进女子组");
   else {
    System.out.println("进男子组");
   }

 } else {

    System.out.println("淘汰");
   }

这样

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请教大神!花括号放在 if (score>80) { 这里为什么会错?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信