Skip to content

Commit 6c00783

Browse files
authored
Update Sum Of All Elements In Array.java
1 parent d43a824 commit 6c00783

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
1-
1+
public class Main
2+
{
3+
4+
static int arrSum(int[] arr, int size){
5+
6+
// base case:
7+
8+
if(size <= 0){
9+
return 0;
10+
}
11+
12+
// recursive relation
13+
14+
return arrSum(arr, size - 1) + arr[size - 1];
15+
}
16+
17+
public static void main(String[] args) {
18+
19+
int size = 5;
20+
int[] arr = {34, 45, 23, 67, 87};
21+
22+
23+
System.out.println(arrSum(arr, size));
24+
}
25+
}

0 commit comments

Comments
 (0)