This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
As per my understanding i==j evaluates to true and as b is false the next thing should be (false= true) which should evaluate to false and hence print false but it prints true.Can any please let me know where I am going wrong...
The reason why it is printing true is that comparison (==) has higher precedence than assignment (=) operator. As such, b=i==j will be evaluated first as: i == j which is 10 == 10, which returns true. The next operation is then b = true, which is assigning true to b. The final code is then read as: if(true) System.out.println("True"); else System.out.println("False"); } So if (true) will print a "True".
Joined: May 24, 2002
Thanks john got it.... [ May 24, 2002: Message edited by: Junaid Khan ]