for (int i = 0; i < 4; i++) { for (int k = 0; k < i; k++) { System.out.print(" "); } for (int j = 4; j > i; j--) { System.out.print("$"); } System.out.println(); }

I was told that the answer when this code segment is printed look's like this:

$$$$

$$$

$$

$

I'm wondering if someone could help me through the steps of reading this code segment as I'm not getting the expected answer.

Here's what I did:

Looking at the outer for loop, (i) 0 < 4 so I went into the first inner nested loop. (k) 0 is not less than (i) 0 so I went to the 2nd inner nested loop and found that it worked, and I was able to repeat this loop 3 more times and then I exited the loop and printed the line out (giving me the first line of four $). I then went back to the outer for loop, increased i by 1 and (i) 1 < 4 so I went to the 1st inner nested loop. I used the 0 for the k first and (k) 0 < 1 so I printed out a space (

**now here's where I get lost**) I then incremented k by 1, so k = 1, but 1 is not less than 1 (i) and so I moved on to the next nested for loop. So when this line is printed, I'll only have one space when there should be 4.

Any help on helping me figure out what I did wrong would be great. Thanks in advance!

Lulu