Headings are not part of the Array

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Write a Java statement that puts a zero into row 5 column 3.

Answer:

gradeTable[ 5 ][ 3 ] = 0;

Headings are not part of the Array

99 42 74 83 100
90 91 72 88 95
88 61 74 89 96
61 89 82 98 93
93 73 75 78 99
50 65 92 87 94
43 98 78 56 99
gradeTable (what is actually in memory)

The 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 store 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 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 ;