Java使用数组实现学分等级分类

package homework;

import java.util.Scanner;

public class CreditRating {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		// 测试数组
		// int score[] = { 72, 89, 65, 58, 87, 91, 53, 82, 71, 93, 76, 68 };
		
		int countA = 0, countB = 0, countC = 0, countD = 0, countE = 0;
		int score[] = new int[12];	
		for (int i = 0; i < score.length; i++) {
			System.out.print("请输入第" + (i + 1) + "个学生的成绩:");
			score[i] = sc.nextInt();
			if (score[i] > 90) {
				countA++;
			} else if (score[i] > 80 && score[i] <= 89) {
				countB++;
			} else if (score[i] > 70 && score[i] <= 79) {
				countC++;
			} else if (score[i] > 60 && score[i] <= 69) {
				countD++;
			} else {
				countE++;
			}
		}

		System.out.println("\n共有" + score.length + "人参加本次测试,测试结果分别为:");
		for (int i = 0; i < score.length; i++) {
			System.out.print(score[i] + "    ");
		}

		System.out.println("\n\n其中A类学员" + countA + "人,B类学员" + countB + "人,C类学员" + countC + "人,D类学员" + countD + "人,E类学员"
				+ countE + "人");

		sc.close();

	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值