Picture of an 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

Answer:

Probably not. It would be useful to have an organized way of reading and storing the values.

Picture of an Array

array

 

An array is an object that is used to store a list of values. It is made out of a contiguous block of memory that is divided into a number of cells. Each cell holds a value, and all the values are of the same type. Sometimes the cells of an array are called slots. In the example array pictured at right, each cell holds an int.

The name of this array is data. The cells are indexed 0 through 9. Each cell can be accessed by using its index. For example, data[0] is the cell which is indexed by zero (which contains the value 23). data[5] is the cell which is indexed by 5 (which contains the value 14).

Facts:

  • The cells are numbered sequentially starting at zero.
  • If there are N cells in an array, the indexes will be 0 through N-1.

Sometimes the index is called a subscript. The expression data[5] is usually pronounced "data-sub-five" as if it were an expression from mathematics: data5.

The value stored in a cell of an array is sometimes called an element of the array. An array has a fixed number of cells, but the values placed in those cells (the elements) may change over time.

QUESTION 2:

What value is in data[7] ?