Write a recursive method that will compute cumulative sums in an array. To find the cumulative sums, add to each value in the array the sum of the values that precede it in the array. For example, if the values in the array are [2, 3, 1, 5, 6, 2, 7], the result will be [2, (2) + 3, (2 + 3) + 1, (2 + 3 + 1) + 5, (2 + 3 + 1 + 5) + 6, (2 + 3 + 1 + 5 + 6) + 2, (2 + 3 + 1 + 5 + 6 + 2) + 7] or [2, 5, 6, 11, 17, 19, 26]. Hint: The parenthesized sums in the previous example are the results of a recursive call.

What will be an ideal response?

```
public static void cumulativeSum(int data[]){
cumulativeSum(data, 1);
}

public static void cumulativeSum(int data[], int n) {
if (n == data.length)
return;
else {
data[n] += data[n-1];
cumulativeSum(data, n+1);
}
}
```

This code is in Methods.java.

Computer Science & Information Technology

You might also like to view...

New blank Word documents are created using the ________ template

A) Normal B) Start-up C) Home D) Blank Document

Computer Science & Information Technology

What does the Windows feature "Sticky Keys" do for users?

a. Tells the computer to ignore quick or repeated keystrokes b. Lets you press key combinations such as (Windows Key+Tab) one key at a time c. Locks down the function key to Enable mode d. Plays a tone when you press Caps Lock, Num Lock, or Scroll Lock

Computer Science & Information Technology