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:

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

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)

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

Share:
19,036
Giovanni Genna
Author by

Giovanni Genna

Updated on June 03, 2022

Comments

  • Giovanni Genna
    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
      D. Ben Knoble over 8 years
      Quick google search reveals the answer
    • Gyuhyeon Lee
      Gyuhyeon Lee almost 4 years
      fun fact is that this is now literally the highest google search for the query "java and or priority"