ArrayPractice.java
package JavaStudy;
//Arrangement pratique Arrangement et total
//Sortie du score moyen et du nombre d'étudiants dans chaque matière
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;
}
}
Recommended Posts