I made a few modifications to the program so that the value of i will be printed from inside the loop expression and the array index expression. The letter A is printed with the loop expression and the letter B is printed with the array index expression. You can see that the value of i is incremented before the array index expression is evaluated. As a result, the value of i exceeds the length of the array on the last iteration of the loop.
If the above is invoked with the following command line:
java X w x y z
Then the output is:
[A,0],[B,1],x
[A,1],[B,2],y
[A,2],[B,3],z
[A,3],[B,4],
The above is followed by an ArrayIndexOutOfBoundsException.
[ January 21, 2003: Message edited by: Dan Chisholm ]