File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Increment operator
ahsan mir
Ranch Hand
Joined: Jul 17, 2006
Posts: 42
posted
Aug 15, 2006 09:53:00
0
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
posted
Aug 15, 2006 09:58:00
0
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
posted
Aug 15, 2006 13:17:00
0
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://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Increment operator
Similar Threads
output
Looping constructs
increment doubt
|| operand
Strange IF condition
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter