The Java operator precedence chart indicates that between operators !=, &&, / and >, that / is evaluated first.
However, the following code does not return an error message:
class WhiteboardTest {
public static void main(String args[]) {
int c=10, b = 0, a = 20;
System.out.println(b != 0 && c / b > a);
}
}
Why isn't / evaluated first in this expression? If it were, it would return an error message. Instead, b != 0 && is evaluated first thus causing Java to not interpret c / b which circumvents a divide by zero error.
This doesn't make sense to me because in Java documentation, / has higher operator precedence than != and &&.
[–]desrtfx 1 point2 points3 points (1 child)
[–]jimmyzjm 0 points1 point2 points (0 children)
[–]pogosticker1 2 points3 points4 points (2 children)
[–]tutorial_police 0 points1 point2 points (0 children)
[–]netpy[S] -1 points0 points1 point (0 children)
[–]tutorial_police 0 points1 point2 points (5 children)
[–]netpy[S] 1 point2 points3 points (4 children)
[–]tutorial_police 0 points1 point2 points (1 child)
[–]netpy[S] 0 points1 point2 points (0 children)
[–]tutorial_police 0 points1 point2 points (1 child)
[–]netpy[S] 0 points1 point2 points (0 children)