java 哪个更优先: || 或 && 或 ==
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33583606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which has more priority: || or && or ==
提问by Giovanni Genna
I have this expression:
我有这样的表达:
y[i] = ( z[i] == a && b || c )
Which of these elements (&&
, ||
, ==
) have the priority?
哪些元素 ( &&
, ||
, ==
) 具有优先级?
Can you please show the order of operations with brackets?
你能用括号显示操作顺序吗?
回答by André Chalella
First ==
, then &&
, then ||
.
首先==
,然后&&
,然后||
。
Your expression will be evaluated as y[i] = (((z[i] == a) && b) || c)
.
您的表达式将被评估为y[i] = (((z[i] == a) && b) || c)
。
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
回答by Alex
The priority list:
优先列表:
- ==
- &&
- ||
- ==
- &&
- ||
回答by numX
This would be :
这将是:
y[i] = ((( (z[i]) == a )&& b) || c)
回答by Magnus J?rgensen
The actual expression is evaluated as
实际表达式被评估为
y[i] = ( ((z[i] == a) && b) || c )
You probably want to look here for more info on operator precedence. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
您可能想在此处查看有关运算符优先级的更多信息。https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
回答by Simon
Here's the full list of ALL OPERATORS:
这是所有运营商的完整列表:
Full list of operators in Java
Got it from "Java ist auch eine Insel" = "Java is also an island"
从“Java ist auch eine Insel”中得到它 =“Java 也是一个岛”