Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can someone walk me through how I got this output?

 
matthew meltzer
Greenhorn
Posts: 24
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34087
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
matthew meltzer
Greenhorn
Posts: 24
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic