Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

AP CSA Question of the Day Feb. 21, 2025

Reference
  1. Incorrect Correct No Answer was selected Invalid Answer

    You have been tasked with writing a program to help score gymnasts at the olympics. You are given a 2D array of values. Each row in the 2D array represents the scores received in a single run. Each column of the 2D array represents the scores given by a particular judge.

    For example, if a gymnast had 3 different runs, and 5 judges scoring each run, their scores 2D array might look like this

    int[][] scores = {
        {9, 8, 9, 9, 10},
        {8, 10, 10, 9, 8},
        {7, 8, 7, 6, 7}
    };
    Java

    What does the following mystery method do?

    public int mystery(int[][] scores) {
        int x = 0;
        int y = 0;
        for (int row = 0; row < scores.length; row++) {
            int a = 0;
            for (int col = 0; col < scores[0].length; col++) {
                a += scores[row][col];
            }
            if (a > x) {
                x = a;
                y = row;
            }
        }
        return y;
    }
    Java