问答详情
源自:4-4 Java条件语句之嵌套 if

麻烦帮我看看下面这段代码哪里错了

public class Wde {
    public static void mian(String[] args) {
            int score=94;
            String sex="女";
            if(score.equals("大于80")) {
            if(sex.equals("男")){
            System.out.println("进入男子决赛");
            }else{
            System.out.println("进入女子决赛");
            }else{
            System.out.println("淘汰");
            }
           
            }
    }
}/*高于80分进入决赛,男的进入男子决赛,女的进入女子决赛 **/

提问者:水杯下的夜空 2017-02-26 13:05

个回答

  • 慕粉4039942
    2017-02-26 15:06:30
    已采纳

    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("淘汰");

    }

    }

    }



    //这会看明白没。  最后一个else是对应最开始判断score的那个if;

  • 慕粉4039942
    2017-02-26 13:23:34

    public class Wde {

    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("淘汰");

    }

    }

    }


    //int  不可以用 equals关键字,equals是判断字符串用的;