This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Increment operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Increment operator" Watch "Increment operator" New topic
Author

Increment operator

ahsan mir
Ranch Hand

Joined: Jul 17, 2006
Posts: 42
hello,
i dont get why the output is x=8 , y=2 and NOT x=4 , y=1.
A step by step solution would be appreciated

***************************************************************************

public class Foozit {

public static void main(String[] args) {

Integer x=0;
Integer y=0;
for(Short z=0;z<5;z++)
if((++x >2)||(++y > 2))
x++;//in the second iteration x starts at 1 and not 2?!
System.out.print(x + " " +y);
}

}

***************************************************************************
ahsan mir
Ranch Hand

Joined: Jul 17, 2006
Posts: 42
Got it!
the x++ only comes into play once x value reaches 3 in the third iteration.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
the x++ only comes into play when x value greater than 2 which is from the third iteration to end.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Increment operator