**
输入学生个数 并输入各学生的成绩 找出最高成绩 并给每个学生判断等级
**
package com.hy.exer;
import java.util.Scanner;
/**
*
- @Description 输入学生个数 并输入各学生的成绩 找出最高成绩 并给每个学生判断等级
- @author lph Email:liupenghao1201@163.com
- @version
- @date 2022年5月15日下午3:39:36
*/
public class AchengjiExer {
public static void main(String[] args) {
// 1.用Scanner,读取学生个数
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生的个数:");
int scan = scanner.nextInt();
// 2.创建数组,存储学生成绩,动态初始化
int[] scores = new int[scan];
// 3.给数组中的元素赋值
System.out.println("请输入" + scan + "个学生的成绩:");
for(int i = 0;i < scores.length; i++) {
scores[i] = scanner.nextInt();
}
// 4.获取数组中的元素的最大值,最高分
int max =0 ;
for(int i= 0; i< scores.length; i++) {
if( max < scores[i]) {
max = scores[i];
}
}
System.out.println("最高分成绩为:" + max);
// 5.根据每个学生的成绩与最高分的差值,得到每个学生的等级,并输出等级和成绩
char len;
for(int i= 0; i< scores.length; i++) {
if( max - scores[i] <= 10) {
len = 'A';
}else if(max - scores[i] <= 20) {
len = 'B';
}else if(max - scores[i] <= 30) {
len = 'C';
}else{
len = 'D';
}
System.out.println("学生 " + (i+1) + " 成绩为 " + scores[i] + " 等级为 " + len);
}
}
}

这是一个Java程序,用于输入学生个数及各学生的成绩,它能找出最高成绩,并根据成绩给每个学生判断等级。代码中包含了注释和作者信息。
1万+

被折叠的 条评论
为什么被折叠?



