【问题标题】:illegal start of expression if statementsif 语句的非法表达式开头
【发布时间】:2017-04-30 05:41:12
【问题描述】:

我不确定 if 语句中的错误在哪里,感谢任何帮助。

导入 java.util.Scanner; 公共类Exercise4P94 {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int carNum;
    boolean chck;
    do {
        chck = true;
        System.out.println("Enter the Car Model Number: ");
        carNum = input.nextInt();

        if (carNum == 119 || carNum == 179 || carNum >== 189 && carNum <== 195 || carNum == 221 || carNum == 780){
            System.out.println("Your car is defective and must be repaired");
        } else if (!(carNum == 119 || carNum == 179 || carNum >= 189 && carNum <= 195 || carNum == 221 || carNum == 780)){
            System.out.println("Your car is not defective");
        } else {
            System.out.println("Please enter a valid car model number");
            chck = false;
        }
    } while (chck);
}

}

【问题讨论】:

  • &gt;==&lt;== 是错误的。应该是&gt;=&lt;=
  • 看看carNum &gt;== 189 &amp;&amp; carNum &lt;== 195 并告诉我是否有什么问题...

标签: java jcreator


【解决方案1】:

在大于/小于号之后不需要两个等号

 carNum >= 189 && carNum <= 195

【讨论】:

  • 该死的。阅读自己时很难看到。谢谢大佬。
  • @EpicNicks 这就是为什么您应该使用能够为您突出显示此类问题的 IDE。
  • 你会推荐哪个?我查看了 Eclipse,而 JCreator 仅用于学校。
  • @EpicNicks Eclipse 不错,也可以试试 IntelliJ(不是免费的)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2021-12-27
  • 1970-01-01
  • 2016-03-17
  • 1970-01-01
  • 2018-08-16
  • 1970-01-01
相关资源
最近更新 更多