查找5个学员成绩的最高分并输出最高分。提示用户一次性输入5位学员的成绩, 使用数组存储用户输入5个数值,然后用循环找出用户输入的最大数值。最后输出最高分
public static void main(String[] args) {
int[] scores = new int[5];
int max = 0;//记录最大值
System.out.println("请输入5位学员的成绩:");
Scanner input = new Scanner(System.in);
for(int i = 0; i < scores.length; i++){
scores[i] = input.nextInt();
}
//计算最大值
max = scores[0];
for(int i = 1; i < scores.length; i++){
if(scores[i] > max){
max = scores[i];
}
}
System.out.println("考试成绩最高分为:" + max);
}