Google

Tuesday, February 17, 2009

Multi-dimensional arrays

Note that the following is all ok:

package practice;

public class Test {

public static void main(String[] args){
int[]one =new int[9];
int[][]two=new int[9][9];
int[][][]three=new int[9][9][9];
int[][][][]bigarray=new int[1][1][1][1];

bigarray[1][1][1][1] = one[2];
bigarray[1][1][1] = one;
bigarray[1][1] = two;
bigarray[1]=three;

bigarray[1][1][1] = two[9];
bigarray[1][1][1] = three[9][9];
}

}


ANALYSIS:

Expecting a single value:

bigarray[1][1][1][1] = ?

so
one[2];

is OK


Expecting a 1-D array:

bigarray[1][1][1] = ?
so
one

is OK

Expecting a 2-D array:

bigarray[1][1] = ?
so
two
is OK

Expecting a 3-D array:

bigarray[1]= ?
so
three
is OK

Expecting a 1-D array:

bigarray[1][1][1] = ?
so
two[9]
is OK

Expecting a 1-D array:

bigarray[1][1][1] = ?
so
three[9][9]
is OK