[JAVA] Array practice

ArrayPractice.java


package JavaStudy;
//Array practice array and total
//Output the average score and the number of students in each subject

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

Array practice
Array practice 2
Array
Array
[Java] array
[Ruby] Array
[Practice] ArrayList
Java array
java (array)
[Practice] ArrayList
Java array
[Java] Array
Java array
ArrayList practice
12 of Array
[Practice] Enumeration
java array
[Java] Array
if else practice
java array variable
About array multiplication
String Buffer practice
JavaScript array manipulation
[Java] Array notes
java practice part 1
Array / list / map
[Practice] Map method
Array is object
Ruby two-dimensional array
Studying Java-Part 7-Array
Ruby array manipulation