在 if else 语句中同时使用多个条件

我有一个涉及使用 Java 的 if else 语句的问题。我被困在如何在括号内放置两个条件,或者这是否可能?


到目前为止,这是我的代码:


public class rollerCoaster {




    int age = 11;

    int weight = 81;


    if ( age <= 10 && weight < 10 ) {

            System.out.println("This person needs to ride the black roller coaster.");

    }

    else if ( age <= 10 && weight >= 80 && <= 200  ) {


    }

    else {


    }


    //The new part is this:


    else if ( condition_two ) {


    }


};


白衣染霜花
浏览 294回答 3
3回答

慕的地6264312

约定类名中的所有FIRTS图表的首字母都需要大写,而代码的结构我认为应该是这样的public class RollerCoaster {static int age = 11;static int weight = 81;public static void main(String args[]) {&nbsp; &nbsp; if(age <= 10) {&nbsp; &nbsp; &nbsp; &nbsp; if(weight < 10) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("This person needs to ride the black roller coaster.");&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }else if(weight >= 80 && weight <= 200) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("This person needs to ride the red roller coaster.");&nbsp; &nbsp; &nbsp; &nbsp; }else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("The roller coaster is not able for this person");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; if(weight < 10) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("This person needs to ride the black roller coaster.");&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }else if(weight >= 80 && weight <= 200) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("This person needs to ride the red roller coaster.");&nbsp; &nbsp; &nbsp; &nbsp; }else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("The roller coaster is not able for this person");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; }}}

叮当猫咪

对于关系运算符 '<=' 您需要提供两个操作数。所以你else if在你的 if 语句中应该是:else&nbsp;if&nbsp;(&nbsp;age&nbsp;<=&nbsp;10&nbsp;&&&nbsp;weight&nbsp;>=&nbsp;80&nbsp;&&&nbsp;weight&nbsp;<=&nbsp;200&nbsp;)&nbsp;{ }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java