Quia



Multiple-Subscripted Arrays

Two dimensional arrays have rows and columns.

Java does not support 2D arrays but does allow the programmer to specify single-subscripted arrays whose elements are single-subscripted arrays.

int num[][]={{5,10},{15,20}};

num[0][0] is 5

num[0][1] is 10

num[1][0] is 15

num[1][1] is 20

The compiler determines the number of rows by counting the number of initializer lists and determines the number of columns by counting the numbert of initialize values.

int matrix[][];

matrix= new int[3][4];

Each row can have a different number of columns.

int notsame [][]={{3,6},{4,8,12}};

Or

int notsame[][];

notsame = new int[2];

notsame[0]= new int[2];

notsame[1]=new int[3];

Use notsame[row].length to traverse the array, where row is the row number(0 or 1).

Look at p344 Fig 7.15

Notice nested for loops

for (int row=0; row ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download