[Java] 纯文本查看 复制代码 package org.yum.rnmb;
import java.util.Random;
import java.util.Scanner;
import static jdk.nashorn.internal.objects.NativeMath.random;
public class HellWorld {
public static void main(String[] args) {
Random random=new Random();
Scanner input=new Scanner(System.in);
System.out.println("请输入班级总组数:");
int team=input.nextInt();
System.out.println("请输入班级中每组的人数:");
int teamStudent=input.nextInt();
double arr[][]=new double[team][teamStudent];
//总不及格数
int count=0;
//总分数
int sum=0;
//创建一个数组保存每组平均数的值
double arTeamArray[]=new double[team];
//给每个学生赋成绩
for (int i = 0; i <team ; i++) {
//初始化下一组不及格人数
int countTeam=0;
//初始化下一组的和
double sumTeam=0;
for(int j=0;j <teamStudent; j++){
arr[i][j]=random.nextDouble()*100;
if(arr[i][j]<60){
//不及格人数+1
countTeam++;
}
sum+=arr[i][j];
sumTeam+=arr[i][j];
}
//添加班级不及格人数
count+=countTeam;
double arTeam=sumTeam/teamStudent;
//给每组平均分赋值
arTeamArray[i] = arTeam;
System.out.println("第"+(i+1)+"组不及格人数为"+countTeam);
System.out.println("第"+(i+1)+"组平均分为"+arTeam);
}
//循环并判断出单组最高平均分
//假设最高平均分为arTeamArray[0]
double Max=0;
for (int i=0;i<team;i++) {
//如果此组大于Max则替换为此组的值
if(arTeamArray[i]>Max){
Max=arTeamArray[i];
}
}
//计算总平均分
int ar=sum/(teamStudent*team);
System.out.println("班级中单组最高平均分是"+Max);
System.out.println("班级中不及格人数为"+count);
System.out.println("班级总平均分为"+ar);
}
}
|