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

前端 未结 5 1801
半阙折子戏
半阙折子戏 2020-12-11 15:29

I have this expression:

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

Which of these elements (&&, ||, ==<

相关标签:
5条回答
  • 2020-12-11 15:51

    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

    0 讨论(0)
  • 2020-12-11 16:07

    The priority list:

    1. ==
    2. &&
    3. ||
    0 讨论(0)
  • 2020-12-11 16:09

    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"

    0 讨论(0)
  • 2020-12-11 16:11

    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

    0 讨论(0)
  • 2020-12-11 16:13

    This would be :

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

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

    0 讨论(0)
提交回复
热议问题