import java.util.Scanner; public class scoreForm { public static void main(String[] args) { //使用Scanner读取学生个数 System.out.println("请输入学生人数"); Scanner scan = new Scanner(System.in); int num = scan.nextInt(); //创建数组,存储学生成绩 int[] arr = new int[num]; //给数组中元素赋值 for (int i = 0; i < arr.length; i++) { System.out.println("第" + (i + 1) + "位学生成绩是"); arr[i] = scan.nextInt(); } //获取最高分,即数组中最大值 int max = arr[0]; for (int i = 0; i < arr.length; i++) { if (max < arr[i]) { max = arr[i]; } } System.out.println("最高分是" + max); //根据规则评定学生成绩
for (int i = 0; i < arr.length; i++) {
if (arr[i] >= max - 10) {
lvl=‘A‘;
} else if (arr[i] >= max - 20) {
lvl=‘B‘;
} else if (arr[i] >= max - 30) {
lvl=‘C‘;
} else {
lvl=‘D‘;
}
System.out.println("第" + (i + 1) + "位学生等级是"+lvl);
}
}
}
原文:https://www.cnblogs.com/xianghaoran/p/12219809.html