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

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

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];
    }
}
A

50

B

54

C

58

D

56

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1mtanarupi22 0m 00s 200
#2kaisuki11 0m 00s 100
#3deltasmpserver11 0m 00s 100
#4y.seong202702 5m 45s -365
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy