aspose file tools*
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: 30768
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can someone walk me through how I got this output?