JAVA第七章第一题

7.1Write a program that reads student scores,gets the best score,and then assigns grades based on the following scheme:
Grade is A if score is>=best-10
Grade is B if score is>=best-20
Grade is C if score is>=best-30
Grade is D if score is>=best-40


import java.util.Scanner;


public class Chapter7point1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("Enter the number of students:");
int len=input.nextInt();
int a[]=new int[len];
int best=0;
System.out.println("Enter "+len+"scores:");
for(int i=0;i<len;i++)
{
a[i]=input.nextInt();
best=a[i]>best?a[i]:best;
}
for(int i=0;i<len;i++)
	System.out.println("Student"+i+"score is"+a[i]+"and grade is"+grade(a[i],best));
	}
	public static String grade(int score,int best){
		 if(score>=best-10)
		  return "A";
		 else if(score>=best-20)
		  return "B";
		 else if(score>=best-30)
		  return "C";
		 else if(score>=best-40)
		  return "D";
		 return "F";
		 
		}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值