Array Traversal and Conditional Sum
Consider the following code segment.
int[] numbers = {3, 7, 2, 9, 1, 5};
int result = 0;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] % 2 == 1) {
result += numbers[i];
}
}
System.out.println(result);
What is printed as a result of executing this code segment?
A
19
B
27
C
25
D
20
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | codexluv | 2 | 2 | 1m 19s | 121 |
| #2 | rsenatatar | 1 | 2 | 0m 06s | 84 |
| #3 | busemagngr | 1 | 1 | 0m 18s | 82 |
| #4 | zhenmunse | 1 | 1 | 0m 18s | 82 |
| #5 | nishanththanasekaran117 | 1 | 1 | 0m 21s | 79 |
| #6 | pgnaiad | 1 | 1 | 0m 33s | 67 |
| #7 | 24uit045 | 2 | 2 | 2m 17s | 63 |
| #8 | muhammadmuso432 | 1 | 1 | 1m 06s | 34 |
| #9 | michael.matveyev | 1 | 1 | 1m 34s | 6 |
| #10 | Potter16 | 1 | 1 | 1m 37s | 3 |
Items per page:
10
1 – 10 of 15
