用java编写比赛分数_编写一个程序,读取学生的分数,获得最高分,然后分配成绩...

有人可以告诉我为什么我的代码没有提供正确的输出?这里有说明“我需要编写一个程序来读取学生的分数,得到最好的分数,然后根据以下方案分配成绩:

1)如果得分> =最佳,则成绩为A - 10

2)如果得分> =最好,等级为B,则为20;

3)如果得分> =最好,等级为C - 30;

4)如果得分> =最好,等级为D - 40;

5)否则等级为F.

程序提示用户输入学生总数,然后提示用户输入所有分数,并通过显示成绩来结束。我的问题来自于从数组中提取等级,这是我到目前为止所做的:// Here is my code. Thank Youimport java.util.Scanner; // imports the scanner functionpublic class NBpractice { //class is formed

public static void main(String []args) { // main method

// user input is asked for the number of students

Scanner input = new Scanner(System.in);

System.out.print("Enter the number of students: ");

int studentNum = input.nextInt();

//user input is asked for students scores

Scanner input2 = new Scanner(System.in);

System.out.print("Enter " + studentNum + " scores: ");

int scores = input2.nextInt();

int best = 80;

char letterGrade;int scoresArray[] = new int[studentNum]; // array is created and holds the # of place values as studentsfor

(int i = 0; i 

//array values are assigned to user's input

best = scoresArray[0];

if (best 

best = scoresArray[i];

}

//-----------------------------------------------------------------------------

if (scores >= (best - 10)) {

letterGrade = 'A';

}

else if (scores >= (best - 20)) {

letterGrade = 'B';

}

else if (scores                    >= (best - 30)) {

letterGrade = 'C';

}

else if (scores >= (best - 30)) {

letterGrade = 'D';

}

else {

letterGrade = 'F';

}

System.out.println("Student " + i + " Score is " + scoresArray[i] + " and grade is: " + letterGrade );

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值