编写一个程序,读入学生成绩,获取最高分best,然后根据下面的规则赋等级值:
如果分数>=best-10,等级为A;
如果分数>=best-20,等级为B;
如果分数>=best-30,等级为C;
如果分数>=best-40,等级为D;
其他情况,等级为F.
import java.util.Scanner;
public class Score {
public static void main (String [] args) {
Scanner input =new Scanner(System.in);
System.out.println("Enter the number of students:");
int number=input.nextInt();
int []score=new int [number];
int best =0;
System.out.println("Enter "+number+" scores:");
for(int i=0;i<number;i++)
score[i]=input.nextInt();
for(int i=0;i<number;i++) {
if (score[i]>=best)
best=score[i];
}
for(int count=0;count<number;count++)
if(score[count]>=best-10)
System.out.println("Student score is "+score[count]+" and grade is A" );
else if(score[count]>=best-20)
System.out.println("Student score is "+score[count]+" and grade is B " );
else if(score[count]>=best-30)
System.out.println("Student score is "+score[count]+" and grade is C" );
else if(score[count]>=best-40)
System.out.println("Student score is "+score[count]+" and grade is D" );
else
System.out.println("Student score is "+score[count]+" and grade is F");
}
}
Enter the number of students:
4
Enter 4 scores:
78 68 78 79
Student score is 78 and grade is A
Student score is 68 and grade is B
Student score is 78 and grade is A
Student score is 79 and grade is A