public static int sum(int[] a, int i) {
if (i >= a.length) return 0;
return a[i] + sum(a, i + 1);
}
// call: sum({1,2,3,4}, 0)What does the call return?
- A
6
- B
0
- C
4
- Dcheck_circle
10
Explanation
1+2+3+4 = 10.
AP Computer Science A· difficulty 2/5
public static int sum(int[] a, int i) {
if (i >= a.length) return 0;
return a[i] + sum(a, i + 1);
}
// call: sum({1,2,3,4}, 0)What does the call return?
6
0
4
10
Explanation
1+2+3+4 = 10.
Want 10 more like this — adaptive to your weak spots?