?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Print Values from Two-Dimensional Array

APCSA-FYEPNB

What is the output from the following segment of code?

int[][] matrix = {{2, 5, 3, 1, 4, 6},
                  {1, 4, 3, 2, 5, 3},
                  {2, 4, 3, 1, 5, 1},
                  {5, 4, 3, 1, 2, 5},
                  {4, 1, 3, 5, 2, 2}};

for (int r=0; r<matrix.length; r++)
{
    for (int c=0; c<matrix[r].length; c++)
    {
        if (matrix[r][matrix[r].length-1]>matrix[r][c])
            System.out.print(matrix[r][c]);
        else
            System.out.print(0);
    }
    System.out.println();
}
A

253140
100200
000000
043120
010000

B

000100
000000
000101
043120
013022

C

203100
143203
243101
000100
010000

D

000000
100000
000000
000000
413022

E

An error is thrown