编写一个程序,读入学生成绩,获取最高分best

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

如果分数>=best-10,等级为A;

如果分数>=best-20,等级为B;

如果分数>=best-30,等级为C;

如果分数>=best-40,等级为D;

其他情况,等级为F.

import java.util.Scanner;

public class Score {
	public static void main (String [] args) {
		
		Scanner input =new Scanner(System.in);
		
	    System.out.println("Enter the number of students:");
		int number=input.nextInt();
		int []score=new int [number];
	    int best =0;
		
	   System.out.println("Enter "+number+" scores:");
	   for(int i=0;i<number;i++) 
		 score[i]=input.nextInt();			   
	       
	      for(int i=0;i<number;i++) {
	    	  if (score[i]>=best)
		        	 best=score[i];	  
	      }
	 
		
		for(int count=0;count<number;count++) 
			if(score[count]>=best-10)
				System.out.println("Student score is "+score[count]+" and grade is A"  );
			else if(score[count]>=best-20)
				System.out.println("Student score is "+score[count]+" and grade is B " );
		    else if(score[count]>=best-30)
			    System.out.println("Student score is "+score[count]+" and grade is C"  );
		    else if(score[count]>=best-40)
		     	System.out.println("Student score is "+score[count]+" and grade is D" );
		    else 
            	System.out.println("Student score is "+score[count]+" and grade is F");
	}

}
Enter the number of students:
4
Enter 4 scores:
78 68 78 79
Student score is 78 and grade is A
Student score is 68 and grade is B 
Student score is 78 and grade is A
Student score is 79 and grade is A

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值