說明直列,帶註釋
/* Declare a two dimensional array, but only specify the first dimension
* of '3'. This effectively leaves three arrays of undefined length
* to which 'arr' can point.
*/
int[][] arr = new int[3][];
/* Declare that arr[0] - the first element in the outer dimension
* is a array of length 5. This creates 5 locations in an array of
* length 5 into which integers can be stored.
*/
arr[0] = new int[5];
/* No further declarations creating new space to store data in arr.
* With no additional operations, below, to allocate memory, there
* may never be more than 5 locations in arr to store anything.
* This means that the rest of the question, as written, is like the
* extra garbage you sometimes get in word problems, to try and confuse
* you
*
* "A train, carrying 1000 apples, is traveling from Des Moines to Boston
* at 90mph. B train, carrying 1 apple, is traveling from Boston to Des Moines
* at 30mph on exactly teh same track. At what point on the track do they
* crash?"
*
* The apples are unnecessary to the problem at hand.
*/
/* Iterate through arr - the outer array of length 3. */
for (int i = 1; i < arr.length; i++)
{
/* Set the current value of arr[i] to the value stored at arr[i-1].
* Remember what each value of arr[] is before entering the loop...
* arr[0] = an array of length 5, whose values are not yet explicitly set
* arr[1] = null
* arr[2] = null
*/
arr[i] = arr[i-1];
/* The first time we get this far, arr[1] will have been set to arr[0]...
* arr[0] = array length 5
* arr[1] = the same length 5 array pointed to by arr[0]
* arr[2] = null
*
* The second time we get this far, arr[1] will have been set to arr[0]...
* arr[0] = array length 5
* arr[1] = the same length 5 array pointed to by arr[0]
* arr[2] = the same length 5 array pointed to by arr[0]
*/
}
來源
2014-01-20 18:50:44
atk
還有就是** **參考在Java歷史名詞 - ARR [i]不拿着** **拷貝改編的[I-1]但是**參考**(指向與arr [i-1]相同的內存),所以對arr [i-1]的任何更改都會立即反映在arr [i]上,反之亦然。這比這更復雜,但基本就是這樣。 :) [幫助教程與圖像解釋參考](http://www.tutorialspoint.com/java/java_arrays.htm)。 – pasty
我明白了,謝謝! – Joshua