1.预备知识:动态数组Array实现;
2.解题过程需要理解的知识:吧唧吧唧吧唧吧唧
不想做了 就用了最简单的方法 和c语言类似
java版本
`import java.util.Scanner;
/.本学期一班级有n名学生,m门课程。现要求对每门课程的成绩进行统计:平均成绩、最高成绩、最低成绩,并统计考试成绩的分布律。/
public class HOME7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入学生数量(n):");
int stu_num= sc.nextInt();
System.out.println("输入课程数量(m):");
int object_num = sc.nextInt() ;
int[][] Stu_Score = new int [stu_num][object_num];
System.out.println("依次输入课程成绩(0-100):");
for(int i = 0;i<stu_num;i++) {
for(int j = 0;j<object_num;j++) {
System.out.printf("第%d个学生的第%d个课程成绩录入:",i+1,j+1);
Stu_Score[i][j] = sc.nextInt();
if(Stu_Score[i][j]<0 || Stu_Score[i][j]>100)
{
System.out.printf("录入失败,重新录入此次成绩");
j--;
}
}
}
ARGE(Stu_Score,stu_num,object_num);//平均值
TOP(Stu_Score,stu_num,object_num);//最高成绩
MINIMUM(Stu_Score,stu_num,object_num);//最低成绩
ANALYSE(Stu_Score,stu_num,object_num);//分布(不及格(<=59)一般(60-79)良好(80-89)优秀(90-100))
sc.close();
}
//每科的平均值
public static double ARGE(int[][] stu,int X,int Y) {
int[] num = new int[X];
for(int i = 0;i<Y;i++) {
for(int j = 0;j<X;j++) {
num[i] += stu[j][i];
}
System.out.printf("第%d科的平均成绩:",i+1);
System.out.println((double)num[i]/X);
}
return 0;
}
//最高成绩
public static double TOP(int[][] stu,int X,int Y) {
int temp = 0;
int[] top = new int[Y];
for(int i = 0;i<Y;i++) {
for(int j = 0;j<X;j++) {
if(stu[j][i]>temp) {
temp = stu[j][i];
}
top[i] = temp;
}
}
for(int h:top) {
System.out.println("每科最高成绩:"+h);
}
return 0;
}
//最低成绩
public static double MINIMUM(int[][] stu,int X,int Y) {
int temp = stu[0][0];
int[] top = new int[Y];
for(int i = 0;i<Y;i++) {
for(int j = 0;j<X;j++) {
if(stu[j][i]<temp) {
temp = stu[j][i];
}
top[i] = temp;
}
}
for(int h:top) {
System.out.println("每科最低成绩:"+h);
}
return 0;
}
public static double ANALYSE(int[][] stu,int X,int Y) {
int[] failed = new int[X];
int[] general = new int[X];
int[] good = new int[X];
int[] outstanding = new int[X];
for(int i = 0;i<Y;i++) {
for(int j = 0;j<X;j++) {
if(stu[j][i]<60) {
failed[i]++;
}
else if(stu[j][i]<80) {
general[i]++;
}
else if(stu[j][i]<90) {
good[i]++;
}
else if(stu[j][i]<101) {
outstanding[i]++;
}
}
}
for(int k = 0;k<Y;k++)
{
System.out.printf("第%d科不及格人数:%d
",k+1,failed[k]);
System.out.printf("第%d科一般人数:%d
",k+1,general[k]);
System.out.printf("第%d科良好人数:%d
",k+1,good[k]);
System.out.printf("第%d科优秀人数:%d
",k+1,outstanding[k]);
}
return 0;
}
}
`