📄 arrayofscores2.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -