Java输入三个班每班三个人,输入成绩,分别计算每个班级的总分和平均分
作者:互联网
代码如下:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int score;
int sum = 0,avg;
for(int i = 1;i <= 3 ;i++) {
sum = 0;
for(int j = 1;j <= 3;j++) {
System.out.println("请输入成绩:");
score = scanner.nextInt();
sum += score;
}
avg = sum/3;
System.out.println("第" + i + "班级的总分是" + sum);
System.out.println("第" + i + "班级的平均分是:" + avg);
}
}
运行结果:
标签:Java,Scanner,int,System,static,输入,平均分 来源: https://www.cnblogs.com/hg-blogs/p/15449645.html