1.输入?个班,每个班?个学生的成绩,成绩为负数的不计算在内,求每个班的总分和平均分
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.print("请输入班级数:");
int classNumber = sc.nextInt();
for (int i = 1; i <=classNumber; i++) {
System.out.print("请输入第"+i+"个班级学生人数:");
int stuNumber =sc.nextInt();
double sum = 0;
double avg = 0;
// 统计分数为正数的人数
int count =0;
for (int j = 1; j <= stuNumber; j++) {
System.out.print("请输入第"+i+"个班第"+j+"个学生的成绩:");
int score =sc.nextInt();
if (score>0){
count++;
sum = score+sum;
// avg = sum/count;
}
avg = sum/count;
}
System.out.println("第"+i+"班级总分为:"+sum);
System.out.println("第"+i+"班级平均分:"+avg);
}