package study;import java.util.Scanner;public class Demo5 { public static void main(String[] args) { Demo5 test2 = new Demo5(); double avg=test2.calcAvg(); System.out.println(">>>该班级的平均成绩是:"+avg); }public double calcAvg() { Scanner input=new Scanner(System.in); int sum=0; int scores[]=new int[4]; for (int i=0;i<scores.length;i++) { System.out.print("请输入第"+(i+1)+"个学生的成绩:"); scores[i]=input.nextInt(); sum+=scores[i]; } return sum/scores.length;}}
添加回答
举报
0/150
提交
取消