Practice Midterm No.2 Flashcards
1
Q
A method that prints an integer array as a parameter and returns the average of all the numbers in that array. For example, if the array was {5,2}, it would return 3.5
A
public static double average(int[] arr){
int sum = 0;
double average = 0;
for (int i = 0; i < arr.length; i++){
sum += arr[i];
}
average = sum / arr.length;
return average;
}