import java.util.Scanner;
public class Deno05 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//输入一个班级的人数
System.out.println("请你输入班级人数:");
int count = sc.nextInt();
//依次输入每个学生的成绩
double[] scores = new double[count];
//遍历数组,保存每个学生的成绩
for (int i = 0; i < scores.length; i++) {
System.out.println("请你输入第"+(i+1)+"个学生的成绩:");
scores[i] = sc.nextDouble();
}
//求出整个班级成绩的平均数
double sum = 0;
for (int i = 0; i < scores.length; i++) {
sum +=scores[i];
}
//求平均数
System.out.println("班级平均成绩是:"+sum/scores.length);
//并打印出最高分和最低分
//假设第一个学生的成绩是最大值
double max = scores[0];
double min = scores[0];
for (int i = 1;i<scores.length;i++){
if (scores[i]>max){
max = scores[i];
}
if (scores[i]<min) {
min = scores[i];
}
}
System.out.println("最大值是:"+max);
System.out.println("最小值是:"+min);
}
}
求和 、平均数、最大值和最小值
于 2022-04-09 09:35:23 首次发布