The below code complies to output b1=false
.
int x=1;
boolean b1 = ++x >= 1 && x++ == 1;
System.out.println("b1="+b1);
But according to the Java Operator Precedence Table it must output b1=true
.
Can any one please explain me step by step what happens?
The order of operators used for this question according to the Java Operator Precedence Table are,
1> postfix - x++
2> unary - ++x
3> relational - >=
4> equality - ==
5> logical AND - &&
The method I used,
1> ++x >= 1 && x++ == 1
2> ++x >= 1 && 1 == 1
now x=2
3> 3 >= 1 && 1 == 1
now x=3
4> true && 1 == 1
5> true && true
6> true
So therefore it should output b1=true
Where have I gone wrong?
What I'm asking is simple, We consider operator precedence over evaluation order for the expression, int x=1+2*3;
BUT why use evaluation order over operator precedence for ++x >= 1 && x++ == 1;
???