

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class ArrayOfScores2
{
    /**
     Reads in 5 scores and shows how much each
     score differs from the highest score.
    */
    public static void main(String[] args) throws IOException
    {
        BufferedReader keyboard = new BufferedReader(
                                       new InputStreamReader(System.in));
        double[] score = new double[5];
        int index;
        double max;
        String inputLine;

        System.out.println("Enter " + score.length + " scores, one per line:");
        score[0] = stringToDouble(keyboard.readLine( ));
        max = score[0];
        for (index = 1; index < score.length; index++)
        {
            score[index] = stringToDouble(keyboard.readLine( ));
            if (score[index] > max)
                 max = score[index];
        //max is the largest of the values score[0],..., score[index].
        }

        System.out.println("The highest score is " + max);
        System.out.println("The scores are:");
        for (index = 0; index < score.length; index++)
            System.out.println(score[index] + " differs from max by "
                                            + (max - score[index]));
    }

    private static double stringToDouble(String stringObject)
    {
        return Double.parseDouble(stringObject.trim( ));
    }
}
