Java Reference
In-Depth Information
four columns are assigned to the first row. Similarly, the number of columns assigned to
the second and third rows are
2
and
3
, respectively (see Figure 9-20).
table
table[0]
2
1
3
5
table[1]
table[2]
15
4
25
23
45
FIGURE 9-20
Array
table
In the remainder of this chapter, we assume that the two-dimensional arrays that are
being considered are not ragged.
A two-dimensional array can be processed in three common ways:
1. Process the entire array.
2. Process a particular row of the array, called row processing.
3. Process a particular column of the array, called column processing.
9
Initializing and printing the array are examples of processing the entire two-dimensional
array. Finding the largest element in a row or column, or finding the sum of a row or
column, are examples of row (column) processing. We will use the following declarations
for our discussion:
static final int
ROWS = 7;
//this can be set to any number
static final int
COLUMNS = 6;
//this can be set to any number
int
[][] matrix =
new int
[ROWS][COLUMNS];
int
sum;
int
largest;
int
temp;
Figure 9-21 shows the array
matrix
.
Search WWH ::
Custom Search