Tracing an ArrayList and For-Each Loop
What is printed when the following code segment is executed?
int total = 3;
ArrayList<Integer> integerList = new ArrayList<Integer>();
for (int k = 7; k < 11; k++)
{
integerList.add(k + 3);
}
for (Integer i : integerList)
{
total += i;
if (total % 2 == 1)
{
total -= 1;
}
}
System.out.println(total);
A
34
B
47
C
49
D
46
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #2 | y.seong2027 | 2 | 3 | 5m 56s | -166 |
| #3 | chunxiangxu.cxu | 0 | 1 | 1h 46m | -6,412 |
Items per page:
10
1 – 3 of 3
APFIVE