* Assignment operators associate from right to left.
* Equality operators associate from left to right.
* Equality operators have greater precedence than assignment operators.
Thus, evaluate the right side first and then perform the assignment. So, i1 does not equal i2 and b1 is set to false. Hope that helps.
Originally posted by Mike Kelly:
Jq-plus Question 955386656992
boolean b1 = false;
int i1 = 2;
int i2 = 3;
if (b1 = i1 == i2)
{
System.out.println("true");
} else
{
System.out.println("false");
}
It will print true.
It will print false.
Correct ans given is false. I disagree because of precedence of operations. The two ints are unequal, which equal the boolean(false) which evaluates to true no? Thanks
[ May 13, 2002: Message edited by: Ricardo Cortes ]