Solved

# Recursive Method to compute cumulative sums in an array

Posted on 2012-09-06

Hi guys!

I'm trying to write this java code where I need to write a recursive method that will compute cumulative sums in an array This is the output I should have

Numbers in array: 2,3,1,5,6,2,7

Output should be: 2,5,6,11,17,19,26

I kind used the Fibonacci method but I'm not sure if I'm doing it right! Here is the code..

public class cumulativearray

{

public static void main (String[] args)

{

int[] array= {2,3,1,5,6,2,7};

System.out.println("The result is:");

System.out.println(sumofarray(array, 0));

}

public static int sumofarray(int[] array, int indicator)

{

if(indicator == array.length)

return 0;

else

return sumofarray(array, indicator - 1) + sumofarray(array, indicator - 2);

}

}