posted 18 years ago
<hr></blockquote>
first loop:
in the first iteration, i is assigned the value of arr[0], which is 1. the line arr[i] = 0 is executed, so now arr[1] = 0. arr is now {1, 0, 3, 4 }. The output to the screen is: 1 0
Second iteration, i = arr[1], so i = 0. arr[i] = 0 executes so now arr[0] = 0. arr is now {0, 0, 3, 4 }. The output to the screen is: 0 0
Third iteration: i = arr[2] so i = 3. arr[i] = 0 executes so now arr[3] = 0. arr is now {0, 0, 3, 0}. The output to the screen is: 3 0
Last iteration: i = arr[3] so i = 0. arr[i] = 0 executes so arr[0] = 0. arr is now {0, 0, 3, 0}. The output to the screen is: 0 0
Finally, the second for loop executes and prints out the modified array. In the code, at each iteration, i is assigned the next value of arr[]. If you followed the first loop, the values in the array at this point should be clear: 0030.
So the final output should look like this:
Make sense?
[ June 13, 2006: Message edited by: Michael Valentino ]
SCJP 1.4, SCWCD J2EE 1.4, SCJD J2SE 1.5, SCBCD J2EE 1.3, SCDJWS (In Progress)