This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is the output? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the output?" Watch "What is the output?" New topic
Author

What is the output?

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167


How can the output of the above program be 13 15 X =6
From where is the 13 coming from

Varuna


Varuna Seneviratna
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

It comes from inside this code:



Why do you think it shouldn't be there?


Steve
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167


From the above statement the output is 15 and a space


From the right above it should be
X = 6;


In the final screen it should be

15 X = 6


I can't figure out from where the 13 is coming from



Varuna
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
Right I just got it the 13 is sent to the screen and X=6 is sent next in the next iteration, with 2 added to 13, that is 15.So finally 13, then in the next iteration 15 X=6 and the final screen looks 13 15 X=6


Am I right?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
Work out what happens when x == 5.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
Originally posted by myself:
Work out what happens when x == 5.


I see you have worked that out; it might be easier to understand if you count forwards!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the output?
 
Similar Threads
how to compare the values in arrays
switch statement example
Logical Operator
P315 K&B puzzle
SCJP 5 Guide by K&B: Q5. Page 391 / 402