我在Java中组织这些if语句时遇到了很多麻烦
16lz
2021-01-22
I have to do a recommend-a-laptop project for school, and I want to keep it as concise as possible by using very long if statements with multiple conditions. I have many of these, but here's one of them:
我必须为学校做推荐的笔记本电脑项目,我希望通过使用具有多个条件的非常长的if语句来尽可能简洁。我有很多这些,但这里有一个:
if
((questionArray [0].equals ("A") && (questionArray [1].equals ("A") || ("B") || ("C") || ("D")) && questionArray [2].equals ("A") && questionArray [3].equals ("A") && questionArray [4].equals ("A") || ("B") || ("C") || ("D"))
{
System.out.println("ASUS Laptop E200HA-UB02-GD 11.6 inch");
}
I am constantly getting, Error: '(' expected and I can't seem to figure it out. Please help!
我经常得到,错误:'('预计,我似乎无法弄清楚。请帮忙!
1 个解决方案
#1
1
After ||
, you need to write questionArray [4].equals("B")...
在||之后,你需要写questionArray [4] .equals(“B”)......
The complete code
完整的代码
if ((questionArray[0].equals("A")) && (questionArray[1].equals("A"))
|| (questionArray[1].equals("B")) || (questionArray[1].equals("C"))
|| (questionArray[1].equals("D")) && (questionArray[2].equals("A"))
&& (questionArray[3].equals("A")) && (questionArray[4].equals("A"))
|| (questionArray[4].equals("B")) || (questionArray[4].equals("C"))
|| (questionArray.equals("D")))
{
System.out.println("ASUS Laptop E200HA-UB02-GD 11.6 inch");
}
The error gone now but I'm not sure whether this code wii work since I never tried mixing the ||
operator with the &&
operator.
错误现在消失但我不确定这段代码是否有效,因为我从未尝试过混合||运算符与&&运算符。
更多相关文章
- 如何判断用户的java代码是否已成功编译?
- 如何获得嵌入式Jetty Web服务器来转储其JSP的临时Java代码
- 急求用jersey2.x+spring3.x 开发rest webservice Java代码实例
- “java.exe”已退出,代码为 1。
- Java错误:线程“main”中的异常java.lang.ArrayIndexOutOfBoundsE
- 不幸的是,在声明按钮时,模拟器中出现了错误
- Java 编程下的同步代码块(售票员)
- JAVA 关于图片上传的代码
- 当我运行.jar时,在java.library中会得到一个“No lwjgl”。路线”