您的位置:首页 > 编程语言 > Java开发

Java语言程序设计-基础篇-6.1习题-指定等级

2015-02-05 20:05 411 查看
 


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


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: