I have a program that I\'m trying to make for class that returns the sum of all the integers in an array using recursion. Here is my program thus far:
public
Try this if you don't want to pass the length of the array :
private static int sumOfArray(int[] array) { if (1 == array.length) { return array[array.length - 1]; } return array[0] + sumOfArray(Arrays.copyOfRange(array, 1, array.length)); }
Offcourse you need to check if the array is empty or not.