Java Reference
In-Depth Information
Display 6.17 Two-Dimensional Array as an Array of Arrays
char [][] a = new char [5][12];
Code that fills the array is not shown.
a
a[1][2]
Blank entries contain the
space (blank) character.
0123456789 0 1
a[0]
Once
upon
a[1]
a
time
a[2]
there
were
a[3]
three
little
a[4]
programmers.
We will see that these can
and should be replaced with
expressions involving the length
instance variable.
int row, column;
for (row = 0; row < 5; row++)
{
for (column = 0; column < 12; column++)
System.out.print(a[row][column]);
System.out.println();
}
Produces the following output:
Once upon
a time
there were
three little
programmers.
A three-dimensional array is an array of arrays of arrays, and so forth for higher
dimensions.
Normally, the fact that a two-dimensional array is an array of arrays need not con-
cern you, and you can usually act as if the array a is actually an array with two indices
(rather than an array of arrays, which is harder to keep track of ). There are, however,
 
Search WWH ::




Custom Search