This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question about if statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question about if statement" Watch "a question about if statement" New topic
Author

a question about if statement

michael wang
Ranch Hand

Joined: Feb 06, 2002
Posts: 35
the code below does compile, so I think
b=i==j can be regarded as
b=true?
is that right? thanks
int i=10;
int j=10;
boolean b=false;
if(b=i==j)
System.out.println("True");


--<br />a java beginner from China
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
You got it!
the code demonstrate operator precedence, it shows that comparisons take place before assignments do
so (b = i == j) is the same as (b=(i==j)) --> (b=true) since i and j have the same value


<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about if statement