For my Java practice midterm, we need to write the exact output of a line of code, in this case, a for loop. Here's the code:
for(int first = 3; first > 0; first--)
for(int second = --first; second <= 5; second++)
System.out.println(first + " " + second);
So I figured the output to be:
2 2
2 3
2 4
2 5
But when I run it in Ecplipse it comes out with:
2 2
2 3
2 4
2 5
0 0
0 1
0 2
0 3
0 4
0 5
I understand how "second" would go from 5 to 0 because of "second <= 5" but I don't see how "first" also resets to 0.
I searched all over for an answer, but couldn't find one. Any help on how this works would be great. Thanks!
first--and the--firstin the code.second <= 5that makessecondgo to zero - it's theint second = --first.