"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
-- Stmt 1 --
I think here, first increment will takes palce and then comparison will be done. hence, the result is else part.
-- Stmt 2 --
If in this case:
if(++i==1)
First, comparison will be done and then increment will takes place.
-- Stmt 3 --
basically, i++ means i=i+1.
so, if(i++==1) will resolve to if((i=i+1)==1)
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Originally posted by krishna:
<snip>
int i=0;
if(i++==1){
System.out.println(" i is equal to 1");
}
else
System.out.println(" i is not equal to 1");
You will get the else part as an output in this case, because the comparison is done first and then the increment of the variable "i" happens.
</snip>
I think here, first increment will takes palce and then comparison will be done. hence, the result is else part.
If in this case:
if(++i==1)
First, comparison will be done and then increment will takes place.
basically, i++ means i=i+1.
so, if(i++==1) will resolve to if((i=i+1)==1)
SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
who dare win!<br />SCJP5(94%)|SCWCD5(86%)|SCBCD(100%)|SCEA in progress