Summing Elements in a 2D Array
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
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #2 | dobaonam8386 | 1 | 2 | 0m 48s | 42 |
| #3 | mullameh001 | 1 | 2 | 1m 16s | 14 |
| #4 | geethasailaja | 0 | 1 | 0m 54s | -64 |
| #5 | ajcantuwilson0325 | 1 | 2 | 3m 47s | -137 |
| #6 | y.seong2027 | 0 | 2 | 3m 20s | -220 |
| #7 | bommasam000 | 1 | 2 | 7m 42s | -372 |
| #8 | ponneban000 | 1 | 1 | 15m 07s | -807 |
| #9 | psak12 | 1 | 1 | 15m 45s | -845 |
APFIVE