从键盘读入学生成绩,找出最高分,并输出学生成绩等级
直接循环输入并判断就行了。
//从键盘读入学生成绩,找出最高分,并输出学生成绩等级。
//等级>=最高分-10,等级为‘A’
//等级>=最高分-20,等级为‘B’
//等级>=最高分-30,等级为‘C’
//其余,等级为‘D’
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("please enter the number of students:");
Scanner scanner =new Scanner(System.in);
int i=scanner.nextInt();
int max_i=0, max=0;
int[] arr=new int[i];
for(int j=0;j<i;j++) {
System.out.println("please enter the score of student"+(j+1));
int scoer=scanner.nextInt();
arr[j]=scoer;
if(scoer>max){
max=scoer;
max_i=j;
}
}
System.out.println("The students with the highest score are :"+(max_i+1)+ ",score is:"+arr[max_i]);
for (int k=0;k<i;k++){
switch((max-arr[k])/10){
case 0:
System.out.println("student "+(k+1)+" score is "+arr[k]+",grade is A");
break;
case 1:
System.out.println("student "+(k+1)+" score is "+arr[k]+",grade is B");
break;
case 2:
System.out.println("student "+(k+1)+" score is "+arr[k]+",grade is C");
break;
default:
System.out.println("student "+(k+1)+" score is "+arr[k]+",grade is D");
break;
}
}
}
}
成绩等级按什么范围划分呢?等级是指A,B,C,D,E吗?