Which has more priority: || or && or ==
19,036
Solution 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
Solution 2
The priority list:
- ==
- &&
- ||
Solution 3
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
Solution 4
This would be :
y[i] = ((( (z[i]) == a )&& b) || c)
Author by
Giovanni Genna
Updated on June 03, 2022Comments
-
Giovanni Genna almost 2 years
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?
-
D. Ben Knoble over 8 yearsQuick google search reveals the answer
-
Gyuhyeon Lee almost 4 yearsfun fact is that this is now literally the highest google search for the query "java and or priority"
-