题目
题目描述与运行示例
*7.1(指定等级)编写一个程序读入学生成绩,得到最高分best,然后根据下面的规则给出等级值。
- 如果分数>=best-10,则等级为A
- 如果分数>=best-20,则等级为B
- 如果分数>=best-30,则等级为C
- 如果分数>=best-40,则等级为D
- 其它情况,等级为F
程序提示用户输入学生总数,然后提示用户输入所有的分数,最后显示等级给出结论。下面是一个运行示例:
Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 0 score is 40.0 and grade is C
Student 1 score is 55.0 and grade is B
Student 2 score is 70.0 and grade is A
Student 3 score is 58.0 and grade is B
破题
- 读入学生个数length,声明数组长度为length
- 读入n个数据(以for循环读入)
- 对n个数据进行比较,获取最大值并赋值给best
- 再定义一个对数组的每个元素进行比较的方法,返回等级
- 博主又增加了一个判断两个数最大值的方法max