Source of Question6.java


  1: import java.util.Scanner;
  2: public class Question6
  3: {
  4:     public static void main(String[] args)
  5:     {
  6:         double[] array = new double[20];
  7:         Scanner keyboard = new Scanner(System.in);
  8:         System.out.println("Enter 20 numbers:");
  9:         for (int index = 0; index < array.length; index++)
 10:             array[index] = keyboard.nextDouble( );
 11:         double lastNumber = array[array.length - 1];
 12:         System.out.println("The last number read is " + 
 13:                             lastNumber + ".");
 14:         System.out.println("The numbers read and their " +
 15:                             "differences from last number are:");
 16:         for (int index = 0; index < array.length; index++)
 17:             System.out.println(array[index] +
 18:                        " differs from the last number by " +
 19:                        (array[index] - lastNumber));
 20:     }
 21: }