求解java编程 急需 谢谢

来源:百度知道 编辑:UC知道 时间:2024/09/20 19:46:32
Assume 30 students are in a class. Generate random numbers ranging from 50 to 100 to be the score of each student. Using the calculations in the last problem, find the frequency of each letter grade, that is, the number of students in each letter grade. Print the number of students getting an “A”, a “B”, a “C, a “D” and an “F” separately.

给30名同学 各取一个50-100的随机数作为分数
然后按照分数 分别取 ABCDEF 6个等级
然后计算各个等级出现的频率 输出各个等级的学生数目?

import java.util.*; //随机数生成器Random
public class student
{
public static void main(String []s)
{
Random ram=new Random() ;//随机数发生器
int score[]=new int[30] ;//30个分数

int A_num=0;
int B_num=0;
int C_num=0;
int D_num=0;
int E_num=0;//分别记录相应等级的学生人数

for(int i=0;i<30;i++)
score[i]=Math.abs(ram.nextInt()%51)+50 ;//0-50的某个数加上50

for(int i=0;i<30;i++)
{
if(score[i]>=90) A_num++ ;
else if(score[i]>=80) B_num++ ;
else if(score[i]>=70) C_num++ ;
else if(score[i]>=60) D_num++ ;
else E_num++ ;
}

System.out.println("A_num="+A_num) ;
System.out.println("B_num="+B_num) ;
System.o