Question
Consider the following mystery methods and that the public mystery method is passed a non-null array filled with integers, and that it is defined to
Consider the following mystery methods and that the public mystery method is passed a non-null array filled with integers, and that it is defined to call the recursive companion method as shown:
public static int mystery(int[] A) {
return mystery(A, 0, A.length - 1);
}
private static int mystery(int[] A, int first, int last) {
if (first == last) return A[first];
int middle = (first + last)/2;
return mystery(A, first, middle) + mystery(A, middle+1, last);
}
Q3). What does method mystery(A) do in general? For this question, assume non-null arrays with lengths > 0.
a). It returns the middle integer value of the array.
b). It returns the sum of indexes of the integers in the array.
c). It returns the sum of the middle two integers in the array.
d). It returns the sum of the integers in the array.
e). It returns double the sum of the integers in the array.
Q4). What is the result of calling mystery(A) if A is a reference to an array with length=0?
a).NullPointerException is thrown.
b). ArrayIndexOutOfBoundsException is thrown.
c). IllegalArgumentException is thrown.
d). Value at A[0] is returned.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started