?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

2-Dimensional Array of Salaries

APCSA-LA1VTS

Consider the following method.

// Print the salaries of all employees of the company
// Each row of salaries is a department.
// Each element is a salary of an employee in that dept.
public static void printSalaries(int[][] salaries)
{
    for (int i=0; i<salaries.length; i++)
    {
        System.out.println(salaries[i]);
    }
}

What is the problem after the following code from a main method is executed?

int[][] salaries = {{50000, 42000, 90000},
                    {120000, 45000, 68000}};
printSalaries(salaries);
A

It throws an ArrayIndexOutOfBoundsException.

B

The salaries do not print correctly because it is not looping through all the rows.

C

The salaries do not print correctly because it is looping through the columns, not the rows.

D

The salaries do not print correctly because it does not refer to the column of the 2-dim array.

E

There is a syntax error in the method.