| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
medium Solved by 12 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

58

B

54

C

56

D

50

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1mtanarupi22 0m 00s 200
#2deltasmpserver11 0m 00s 100
#3kaisuki11 0m 00s 100
#4midnightasdark13 0m 41s 39
#5y.seong202702 5m 45s -365
Items per page:
10
1 – 5 of 5
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy