| preferred AP College board partner for AP classes
Login
 
Register
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
2D Array Traversal and Summation
< Prev
Next >

What is the value of sum after the code segment is executed?
Refer to the following code segment.

int[][] matrix = {
    {1, 2, 3, 4},
    {5, 6, 7, 8},
    {9, 10, 11, 12}
};
int sum = 0;
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
        if (matrix[i][j] % 3 == 0) {
            matrix[i][j] /= 3;
        }
        sum += matrix[i][j];
    }
}
System.out.println(sum);

What is the value of sum after the code segment is executed?

A

50

B

54

C

56

D

58

Check Answer
APFIVE © 2020.
Email: [email protected]|Privacy Policy