哪个优先级更高:||或 && 或 ==

Which has more priority: || or && or ==

我有这样的表达:

y[i] = ( z[i] == a && b || c )

这些元素(&&||==)中哪些元素具有优先级?

你能用括号显示操作顺序吗?

首先是==,然后是&&,然后是||

您的表达式将被计算为 y[i] = (((z[i] == a) && b) || c)

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

这将是:

y[i] = ((( (z[i]) == a )&& b) || c)

参考:http://introcs.cs.princeton.edu/java/11precedence/

实际表达式的计算结果为

y[i] = ( ((z[i] == a) && b) || c )

您可能想在此处查看有关运算符优先级的更多信息。 https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

优先列表:

  1. ==
  2. &&
  3. ||

这是所有运营商的完整列表:

Full list of operators in Java

来自 "Java ist auch eine Insel" = "Java is also an island"