import java.util.Scanner; public class Rain { public static void main(String[] args) { // Declare and allocate an array of doubles of size 4 double[] a; a = new double[4]; // Explicitly initialize all 4 elements a[0] = 10.1; a[1] = 12.3; a[2] = 9.7; a[3] = 8.2; // Sum the elements double sum = 0; int i = 0; while (i < a.length){ sum = sum + a[i]; i = i + 1; } System.out.println(sum); // Reassign the elements by reading from the keyboard // The loop needs a prompt to tell the user to input a double Scanner s = new Scanner(System.in); i = 0; while (i < a.length){ a[i] = s.nextInt(); i = i + 1; } // Print all 4 elements, first to last i = 0; while (i < a.length){ //while (i < 4){ System.out.println("i is " + i + " a[i] is " + a[i]); i = i + 1; } System.out.println( ); // Print all 4 elements, last to first i = a.length - 1; while (i >= 0 ){ System.out.println("i is " + i + " a[i] is " + a[i]); i = i - 1; } } }