arrayofscores2.java

来自「java编程代码」· Java 代码 · 共 36 行

JAVA
36
字号


import java.util.Scanner;

public class ArrayOfScores2
{
    /**
     Reads in 5 scores and shows how much each
     score differs from the highest score.
    */
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        double[] score = new double[5];
        int index;
        double max;

        System.out.println("Enter " + score.length + " scores:");
        score[0] = keyboard.nextDouble( );
        max = score[0];
        for (index = 1; index < score.length; index++)
        {
            score[index] = keyboard.nextDouble( );
            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]));
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?