More Complicated Example

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:

C:/users/default>java ArrayEg2

cell 3: 0.0
cell 2: 2.98
cell 1: 1.43

More Complicated Example

Here is a more complicated example of array subscripting:

class ArrayEg3
{
  public static void main ( String[] args )
  {
    double[] val = new double[4];  

    val[0] =  1.5;
    val[1] = 10.0;
    val[2] = 15.5;

    int j  = 3;
    val[j] = val[j-1] + val[j-2];   // same as val[3] = val[2] + val[1]

    System.out.println( "val[" + j + "] == " + val[j] );
 
   }
}

QUESTION 10:

What does the above program print out?

val [ ] ==