We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 22c2355 commit 440db4fCopy full SHA for 440db4f
03_recursion/java/04_sum/src/Sum.java
@@ -0,0 +1,19 @@
1
+import java.util.*;
2
+
3
+public class Sum {
4
+ public static int sum(ArrayList<Integer> num_list, int index) {
5
6
+ if (num_list.size() == index) {
7
+ return 0;
8
+ } else {
9
+ int num = num_list.get(index);
10
+ return num + sum(num_list, index + 1);
11
+ }
12
13
14
15
+ public static void main(String[] args) {
16
+ int total = sum(new ArrayList<Integer>(Arrays.asList(2, 4, 6)), 0);
17
+ System.out.println(total);
18
19
+}
0 commit comments