February 2014
Beginner
1248 pages
62h 25m
English
Many common array manipulations use for statements. As an example, the following for statement sets all the elements in row 2 of array a in Fig. 7.16 to zero:
for (int column = 0; column < a[2].length; column++) a[2][column] = 0;
We specified row 2; therefore, we know that the first index is always 2 (0 is the first row, and 1 is the second row). This for loop varies only the second index (i.e., the column index). If row 2 of array a contains four elements, then the preceding for statement is equivalent to the assignment statements
a[2][0] = 0;a[2][1] = 0;a[2][2] = 0;a[2][3] = 0;
The following nested for ...
Read now
Unlock full access