Score: 34/40

This is an image

Corrections:

Question 15

This is an image

The correct answer is A: I only. II is an incorrect option because once k reaches data.length-1, there will be an exception because it will not be able to check the next term as it does not exist. I is a correct option because if the previous value is greater than the current value, false is returned because the sequence of numbers would be decreasing rather than increasing.

Question 16

This is an image

The correct answer is D: k+a1.length. All the values of a1.length-1 is already taken by the first for loop. k+a1.length will access the the elements of a2 and add them to the array.

Question 18

This is an image

The correct answer is B (int) ( Math.random () * myList.size () ). The int function initializes values 0 and myList.size() – 1 inclusive. Math.random generates a random value 0 to 1 not including 1. It is then multiplied by myList.size to determine a random value in the list.

Question 30

This is an image

The correct answer is C: “ilercom”. The int howFar starts at 3, word.substring(howFar + 1, word.length()) is “iler”. Then word.substring(0, howFar) adds “com” to the end.

Question 39

This is an image

The correct answer is D: 16. Since 27 is greater than 10, the call returns recur(recur(9)). recur(9) returns 18 since 9 is less than 10. recur(18) then returns recur(recur(6)). recur(6) returns 12. recur(12) returns recur(recur(4)). recur (4) returns 8 and recur(8) returns 16 finally.

Question 40

This is an image

The correct answer is C: W/WA/WAT/WATC. whatsItDo(temp) is a recursive call and since it is placed before the line System.out.println(temp), it goes through WATC, WAT, and WA before reaching the base. It then prints from W to WATC due to the recursive call.

Notes

  • array lists always start from term 0
  • compile: will code execute?
  • calling manipulate
  • int x : arr sets x as each value of the array
  • recursions repeat the code and reenter value into loop
    • stops when returns a final value
  • if printing an integer and calculation leads to decimal - round number
  • Math.abs finds the absolute value of the function
  • ! reverses what is inside the criteria and changes && to   and vice versa