Array 问题

sevendays 2012-04-03 12:01:49
让用户输入学生总数和学生的成绩,程序得出学生的等级并且显示出来。
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
Grade is "F" otherwise.
示例如下
Enter the number of students: 4
Enter 4 scores:
40
55
70
58
RESULTS ARE DISPLAYED BELOW:
Student 1 score is 40 and grade is C
Student 2 score is 55 and grade is B
Student 3 score is 70 and grade is A
Student 3 score is 58 and grade is B
我写的代码如下,但是无法运行,不知道为什么
import java.util.Scanner;
public class grades {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.print("Enter the number of students:");
int z=input.nextInt();
double[] scores=new double[z];
System.out.print("Enter"+scores.length+"scores:");
for (int i=0;i<scores.length;i++){

scores[i]=input.nextDouble();

}
for (int i=0;i<scores.length;i++){
if (scores[i]>=90)
System.out.println("Student "+i+"score is"+scores[i]+
"and grad is A");
else if (scores[i]>=80)
System.out.println("Student "+i+"score is"+scores[i]+
"and grad is B");
else if (scores[i]>=70)
System.out.println("Student "+i+"score is"+scores[i]+
"and grad is c");
else if (scores[i]>=60)
System.out.println("Student "+i+"score is"+scores[i]+
"and grad is D");
else
System.out.println("Student "+i+"score is"+scores[i]+
"and grad is F");
...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
成一粒 2012-04-03
  • 打赏
  • 举报
回复
怎么不能运行?
菖蒲老先生 2012-04-03
  • 打赏
  • 举报
回复
类名最好用大写。。。
sevendays 2012-04-03
  • 打赏
  • 举报
回复
哈哈 不好意思 我又试了一下 可以运行,乌龙了~~~

50,549

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧