Using Arrays

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

What value is in data[7] ?

Answer:

103

Using Arrays

Before After

data[3] = 99 ;

 

 

Every cell of an array holds a value of the same type. So, for example, you can have an array of int, an array of double, and so on.

You can have an array of object references. This is discussed in a later chapter.

The array on the left holds data of type int. Every cell contains an int. A cell of this array can be used anywhere a variable of type int can be used. For example,

data[3] = 99 ; 

works just like an assignment to an int variable. After it has been executed, the array looks like the picture on the right.

The value in cell 3 of the array has been changed.

QUESTION 3:

What do you suppose is the value of the arithmetic expression:

data[2] + data[6]