Ask Question

Write the method public static doublell quizAverages (double (1 scores). which takes a 2D array of doubles that represent quiz scores for students in a course and returns an array of quiz averages. Specifically, each column represents a quiz, and each row represents a student in the class. Therefore, what the method returns is an array of column averages, essentially. Assume that all students take the same number of quizzes

+2
Answers (1)
  1. 6 August, 08:42
    0
    import java. util. Arrays; public class Main { public static void main (String[] args) { double [][] studentScores = { {78, 40, 97}, {89, 90, 68}, {70, 35, 88} }; System. out. println (Arrays. toString (quizAverages (studentScores))); } public static double[] quizAverages (double [][] scores) { double average[] = new double[scores[0]. length]; for (int col = 0; col < scores[0]. length; col++) { double sum = 0; for (int row = 0; row < scores. length; row++) { sum + = scores[row][col]; } average[col] = sum / scores[col]. length; } return average; } }

    Explanation:

    The solution code is written in Java.

    Firstly, create a static method that take one input parameter, double type two dimensional arrays and this method will return one array of average as required by question (Line 11).

    In the method, declare a double type array and initialize its size with the length of the column of the input scores array (Line 12).

    Create a double layer of for loop with outer loop to iterate through the column of the input score array and the inner loop to iterate through the row (Line 13-15). In the outer loop, create a sum variable to hold the value of summation for each column (Line 14). In the inner loop, increment the sum variable with the score in each row (Line 16). After finishing one inner loop cycle, the sum is divided by the length of column and assign it to an item of average array in outer loop before proceed to the next round of outer loop to repeat the same process (Line 18).

    At last return the average array (Line 20).

    We can test the method using a sample data (Line 4-8) and print out the output returned by the method (Line 9).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the method public static doublell quizAverages (double (1 scores). which takes a 2D array of doubles that represent quiz scores for ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers