Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


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: 32481
    
214

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!
 
Have you checked out Aspose?
 
subject: Can someone walk me through how I got this output?
 
It's not a secret anymore!