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

久未见 提交于 2019-12-01 14:28:18

问题


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?


回答1:


First ==, then &&, then ||.

Your expression will be evaluated as y[i] = (((z[i] == a) && b) || c).

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




回答2:


The priority list:

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



回答3:


This would be :

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

ref: http://introcs.cs.princeton.edu/java/11precedence/




回答4:


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




回答5:


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"



来源:https://stackoverflow.com/questions/33583606/which-has-more-priority-or-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!