Two Dimensional Arrays

This chapter expands our discussion on one-dimensional arrays to two dimensional arrays. A two dimensional array is a data structure that contains a collection of cells laid out in a two dimensional grid, similar to a table with rows and columns although the values are still stored linearly in memory. Each cell in a two dimensional array can be accessed through two indexes that specify the row number and column number respectively. Like s one dimensional array, the range of each index is from zero to the size of the row or column minus one. A nested for loop is commonly used to initialize, manipulate, and access the values in a two dimensional array.

4. Headings are not part of the Array


Answer:

gradeTable[ 5 ][ 3 ] = 0;

Headings are not part of the Array

Annotation 2020-03-26 205058The row and column numbers are not part of the array. They are usually shown in pictures of an array, but the array object does not explicitly contain the indexes. When you ask for

gradeTable[ 5 ][ 3 ]

Java knows what cell you mean and goes there directly.

More Important Stuff:

      • Rows are numbered from 0 to N-1, where N is the number of rows
      • Columns are numbered from 0 to M-1, where M is the number of columns.
      • A 2D array with N rows and M columns per row will have N times M number of cells.
      • However, it is possible for a 2D array to have a different number of cells in each row.

Details about these issues will follow.


Question 4:

With the example array, will the following statement work?

gradeTable[7][2] = 82 ;