Summe der Array -Rekursion Java
// Sum of Array Elements with recursion - Java
public class SumOfArrayElementsRecursion {
private static int Sum(int arr[], int n) {
if (n <= 0) { //base case
return 0;
}
return Sum(arr, n-1 ) + arr[n-1]; //Recursive call
}
public static void main(String[] args) {
int arr[] = {1, 2, 3, 4, 5, 5};
int sum = Sum(arr, arr.length);
System.out.println(sum);
}
}
eeee