ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
int run = 0;
ArrayList<Integer> result = new ArrayList<>();
for (int x : list) {
run += x;
result.add(run);
}
System.out.println(result);What is printed?
- Acheck_circle
[1, 3, 6, 10]
- B
[1, 2, 3, 4]
- C
[10, 6, 3, 1]
- D
[0, 1, 3, 6]
Explanation
Running sums: 1, 1+2=3, 3+3=6, 6+4=10.