This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Can someone walk me through how I got this output? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can someone walk me through how I got this output?" Watch "Can someone walk me through how I got this output?" New topic
Author

Can someone walk me through how I got this output?

matthew meltzer
Greenhorn

Joined: Sep 08, 2012
Posts: 24

the code is



And the output is
i=1, j=0
i=2, j=0
i=2, j=1


I'm just trying to understand how j remains 0 for the first two lines the program prints.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32628
    
215

I've added code tags to make the code easier to read.

Each time the outer loop runs, the inner loop "starts over." Therefore, it starts as j=0 for each new value of i.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
matthew meltzer
Greenhorn

Joined: Sep 08, 2012
Posts: 24

Jeanne Boyarsky wrote:I've added code tags to make the code easier to read.

Each time the outer loop runs, the inner loop "starts over." Therefore, it starts as j=0 for each new value of i.


That makes sense. Thank you.

And I thought I put code tags around it but must have forgotten. Sorry about that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can someone walk me through how I got this output?
 
It's not a secret anymore!