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...

____ is the practice of intercepting signals with a Wi-Fi enabled notebook.

A. LANjacking B. War driving C. Keylogging D. Both A and B.

Computer Science & Information Technology

The ____ operator is used to concatenate two strings.

A. & B. # C. @ D. +

Computer Science & Information Technology

An object is an aspect of a counter that can be monitored.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

_____ variables are variables whose values are determined when the query is run by the processor.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology