File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about if statement

 
michael wang
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic