*
The moose likes Beginning Java and the fly likes Please help me to figure out confusion with my program output. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help me to figure out confusion with my program output. " Watch "Please help me to figure out confusion with my program output. " New topic
Author

Please help me to figure out confusion with my program output.

rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1

Hi Guys.

Please help me to understand code given below. I tried to find the value for i. Few times i counted as 2. But finally i counted as 3 which is correct answer.
I just want to know, have i taken correct method to figure out the value for i.

This is how i counted.
b = false
i = 1
i++ increment i by 1. so new value of i is now 2.
b= !b means b's value assigned to true.
finally reach to while condition and its( value or b is) true. so loop continue.
increment i by 1. New value for i is 3
b= !b, Therefore b = false
Reach the while condition and its false. So go out from while loop and print 3.

Please help me to understand whether i have taken right path to figure out value of i.
Thank you in advance



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Yes, I think you have. I tried your code and got 3.
rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
I just wanted to know whether i have followed correct path to get the output.
Thank you for you reply
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Yes, you reasoned correctly. Well done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me to figure out confusion with my program output.
 
Similar Threads
Code using Loops
Unexpected output ??
do while loop problem
Loops
while loop