/* * This program demonstrates arrays. * Arrays are an indexed collection of variables that use the same name, are of the same type and are in continuous memory locations. * In this program, we will demonstrate arrays of primitive types, declraring and initializing arrays and passing arrays as * parameters to methods. */ import java.util.Scanner; class ArrayExample { public static void main (String [] args) { Scanner input = new Scanner (System.in); //Arrays are set up in two steps. We need to declare them first and then create the array. //Here, we create an array of 10 doubles. // Step 1: declaration. This just creates a reference to the array. The array doesn't exist yet. double [] myArray; //Step 2: Actually create the array. Memory allocation happens here. myArray = new double[10]; // The 2 steps can be combined into double [] myArray = new double[10]; //Reading in 10 doubles from the user. System.out.println("Please enter 10 floating point variables."); //Arrays and for loops work very well together. We are going to use a for loop to read in 10 values. for(int i=0; i