Write a recursive method that will compute the sum of all the values in an array.

What will be an ideal response?


```
public static int sumArray(int [] data){
return sumArray(data, data.length-1);
}

public static int sumArray(int [] data, int last){
int result;

if(last < 0)
result = 0; // only one value in the subarray
else{
result = data[last] + sumArray(data, last-1);
}

return result;

}
```

This code is in Methods.java.

Computer Science & Information Technology

You might also like to view...

MC The______keyword tests whether a value is in a sequence.

a) search. b) in. c) contains. d) None of the above.

Computer Science & Information Technology

What is the number of approaches to algorithm design?

a. Many b. 3 c. 4 d. 5

Computer Science & Information Technology

The output of the Java code:int alpha = 5;int beta = 4;switch (beta){case 2:     alpha = alpha + 2;case 4:     alpha = alpha + 4;    break;case 6:     alpha = alpha + 6;default:      alpha = alpha + 10;}System.out.print(alpha); is: 9

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

Computer Science & Information Technology

A program is executed in 200 ms, during which 250 million instructions are executed. What is the average MIPS rating for this program?

What will be an ideal response?

Computer Science & Information Technology