Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the code below for the next two questions. int[] a = {3, 4, 2, 1, 5, 6, 9, 2

ID: 3582628 • Letter: U

Question

Use the code below for the next two questions.

int[] a = {3, 4, 2, 1, 5, 6, 9, 2, 1, 3};

public int myMethod (int[] a, int x, int y) {

if (x <= y)

return a[y] + myMethod (a, x, y-1);

else

return 0;

}

What is returned from invoking myMethod(a, 3, 7)?

What is returned from invoking myMethod(a, 6, 2)?

What is returned by invoking doSomething(6, 3)?

public int doSomething(int x, int y){

if (x == y)

return 0;

else

return 2 + doSomething(x-1, y);

}

Calling the doSomething method from the previous question will result in infinite recursion if which condition is initially true?

Select one:

x == y

x != y

x < y

x > y

Explanation / Answer

What is returned from invoking myMethod(a, 3, 7)?
a[7] + a[6] + a[5] + a[4] + a[3] = 1 + 5 + 6 + 9 + 2 = 23

What is returned from invoking myMethod(a, 6, 2)?
0

What is returned by invoking doSomething(6, 3)?
2 + 2 + 2 = 6

Calling the doSomething method from the previous question will result in infinite recursion if which condition is initially true?
x < y