Edited at

配列の練習


ArrayPractice.java

package JavaStudy;

//配列の練習 配列と合計
//各科目の平均点数と生徒数を出力

public class ArrayPractice {

public static void main(String[] args) {

int[]Math = {45,68,97,35,44,61,0,25,97,11,100};
int[]English = {54,79,12,65,67,59,43,81,5,98,41,20};
int[]Science = {64,38,73,49,35,71,10,21,55,71};

int result1 = resultAverage(Math,resultSum(Math));
int result2 = resultAverage(English,resultSum(English));
int result3 = resultAverage(Science,resultSum(Science));

printResult(Math,result1);
printResult(English,result2);
printResult(Science,result3);
}

public static void printResult(int[]subject,int average) {
System.out.println("Average score is "+ average);
System.out.println("There are "+ subject.length +" students");
}

public static int resultSum(int[]subject) {
int sum = 0;
for(int i =0;i < subject.length;i++) {
sum = sum + subject[i];
}
return sum;
}

public static int resultAverage(int[]subject,int resultSum) {
int average = 0;
average = resultSum/subject.length;
return average;
}

}