(指定等级）编写一个程序，读入学生成绩，获取最髙分best, 然后根据下面的规则陚等级值

• 如果分数>=best-10, 等级为A

• 如果分数>=best-20, 等级为B

• 如果分数>=best-30, 等级为C

• 如果分数>=best-40, 等级为D

• 其他情况下，等级为F

``````Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B``````

``````// https://cn.fankuiba.com
import java.util.Arrays;
import java.util.Scanner;

public class Ans7_1_page235 {
public static void main(String[] args) {
String[] grade = {"A","B","C","D","F"};
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int number = input.nextInt();
System.out.print("Enter " + number + " scores: ");

int[] score = new int[number];
for (int i = 0; i < number; i++)
score[i] = input.nextInt();

int[] scoreSort = new int[number];
System.arraycopy(score,0,scoreSort,0,score.length);

Arrays.sort(scoreSort);

int maxSort = scoreSort[number-1];
for (int i = 0; i < number; i++) {
if (score[i] >= maxSort-10)
System.out.println("Student " + i + " score is " + score[i] +
" and grade is " + grade);
else if (score[i] >= maxSort-20)
System.out.println("Student " + i + " score is " + score[i] +
" and grade is " + grade);
else if (score[i] >= maxSort-30)
System.out.println("Student " + i + " score is " + score[i] +
" and grade is " + grade);
else if (score[i] >= maxSort-40)
System.out.println("Student " + i + " score is " + score[i] +
" and grade is " + grade);
else
System.out.println("Student " + i + " score is " + score[i] +
" and grade is " + grade);
}
}
}``````