编写一个程序,读入学生成绩,获取最高分best,然后根据下面的规则赋等级值。

  1. 题目要求
    编写一个程序,读入学生成绩,获取最高分best,然后根据下面的规则赋等级值。
  • 如果分数>=best-10,等级为A
  • 如果分数>=best-20,等级为B
  • 如果分数>=best-30,等级为C
  • 如果分数>=best-40,等级为D
  • 其他情况下,等级为F
    程序提示用户输入学生总数,然后提示用户输入所有的分数,最后显示等级得出结论。下面是一个运行实例:
    在这里插入图片描述
  1. 参考代码
import java.util.Scanner;
public class Grade {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input=new Scanner(System.in);
        System.out.print("Enter the number of students: ");
        int students=input.nextInt();
        int []scores=new int[students];
        System.out.print("Enter "+students+" scores:");
        int maxscore=0;
        for(int i=0;i<scores.length;i++){
            int score=input.nextInt();
            scores[i]=score;
            if(scores[i]>maxscore)
                maxscore=scores[i];}
        for(int i=0;i<scores.length;i++){
            char level;
            if(scores[i]>=maxscore-10)
            level='A';
            else if(scores[i]>=maxscore-20)
            level='B';
            else if(scores[i]>=maxscore-30)
            level='C';
            else if(scores[i]>=maxscore-10)
            level='D';
            else 
            level='F';
        System.out.println("Student "+i+" scores is "+scores[i]+" and grade is "+level);}
    
      
            
        }
    }
   
  1. 运行结果截图
    在这里插入图片描述
  • 7
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值