| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
medium Solved by 10 students
Summing Elements in a 2D Array
< Prev
Next >

Consider the following code segment.

int[][] arr = {{1, 2, 3, 4},
               {5, 6, 7, 8},
               {9, 10, 11, 12}};

int sum = 0;
for (int[] x : arr)
{
    for (int y = 0; y < x.length - 1; y++)
    {
        sum += x[y];
    }
}

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

A

78

B

68

C

36

D

54

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki12 0m 00s 90
#2dobaonam838612 0m 48s 42
#3mullameh00112 1m 16s 14
#4geethasailaja01 0m 54s -64
#5ajcantuwilson032512 3m 47s -137
#6y.seong202702 3m 20s -220
#7bommasam00012 7m 42s -372
#8ponneban00011 15m 07s -807
#9psak1211 15m 45s -845
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy