从键盘读入学生成绩,找出最高分,并统计学生成绩等级人数

该博客介绍了如何使用Java编程,从键盘接收学生成绩,计算最高分,并根据预设成绩等级标准(A、B、C、D)统计各等级学生的人数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从键盘读入学生成绩,找出最高分,并统计学生成绩等级人数。
成绩=100 等级为’A’
成绩>=80 等级为’B’
成绩>=60 等级为’C’
其余 等级为’D’

import java.util.Scanner;
public class Scores {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.print("请输入学生个数n:");
		int n = s.nextInt();
		
		int scores[] = new int[n];//创建数组存放成绩
		for(int i = 0;i<scores.length; i++) {
			int j = i + 1;
			System.out.print("请输入第"+j+"个学生成绩:");
			scores[i] = s.nextInt();
		}
		
		int maxScore = 0;//最高分
		int a = 0;//成绩等级
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i = 0; i < scores.length; i++) {
			if(maxScore < scores[i]) {
				maxScore = scores[i];
			}
			if(scores[i]==100) {
				a++;
			}else if(scores[i]>=80) {
				b++;
			}else if(scores[i]>=60) {
				c++;
			}else {
				d++;
			}
		}
		System.out.println("最高分为:"+maxScore);
		System.out.println("A等级人数为:"+a);
		System.out.println("B等级人数为:"+b);
		System.out.println("C等级人数为:"+c);
		System.out.println("D等级人数为:"+d);
	}

}

import java.util.Scanner;

public class Scores1 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.print("请输入学生个数n:");
		int n = s.nextInt();
		
		int scores[] = new int[n];//创建数组存放成绩
		for(int i = 0;i<scores.length; i++) {
			int j = i + 1;
			System.out.print("请输入第"+j+"个学生成绩:");
			scores[i] = s.nextInt();
		}
		
		int maxScore = 0;//最高分
		//学生成绩等级
		char grade[] = new char[] {'A','B','C','D'};
		int count[] = new int[4];//统计成绩等级人数
		for(int i = 0; i < scores.length; i++) {
			if(maxScore < scores[i]) {
				maxScore = scores[i];
			}
			if(scores[i]==100) {
				count[0]++;
			}else if(scores[i]>=80) {
				count[1]++;
			}else if(scores[i]>=60) {
				count[2]++;
			}else {
				count[3]++;
			}
		}
		System.out.println("最高分为:"+maxScore);
		for(int i = 0; i<grade.length; i++) {
			System.out.println(grade[i]+"等级人数为:"+count[i]);
		}

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

什么都不懂的菜鸟玩家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值