We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cc5ebe8 commit 8a51e2dCopy full SHA for 8a51e2d
ArraySum.java
@@ -0,0 +1,18 @@
1
+class ArraySum {
2
+ public static int iterativeSum(int[] arr) {
3
+ int sum = 0;
4
+ for (int i = 0; i < arr.length; i++) {
5
+ sum += arr[i];
6
+ }
7
+ return sum;
8
9
+
10
+ public static int recursiveSum(int[] arr) {
11
+ return recursiveSum(arr, 0)
12
13
+ public static int recursiveSum(int[] arr, int index) {
14
+ if (index == arr.length)
15
+ return 0;
16
+ return arr[index] + recursiveSum(arr, index + 1);
17
18
+}
0 commit comments