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";
}
}