Score: 38/40
MCQ Corrections
- I got this question wrong as I forgot how integer division works in Java. The correct answer is (C) as x satisfies the first half of the conditional as it is less than 10 by y does not satisfy the first half of the conditional since y is greater than 0. As a result the conditional evaluates to False and the second part of the if conditional is run giving the output 7/3. In Java, integer division also outputs an integer so the true quoteint of 2.333 will be truncated to 2 when printing.
- I got this question wrong due to an improper understanding of recursion and not paying careful attention to each of the options. (C) is the correct answer as the call whatsItDo(“WATCH”) sets temp to the substring of “WATCH” from index 0 to 3 (4 - 1), resulting in “WATC”. It then recursively calls whatsItDo(“WATC”). In whatsItDo(“WATC”), temp becomes “WAT”, and it calls whatsItDo(“WAT”). Similarly, whatsItDo(“WAT”) sets temp to “WA” and calls whatsItDo(“WA”), which sets temp to “W” and calls whatsItDo(“W”). At this point, the base case is reached since the length of “W” is 1, so no further action is taken. Returning from the recursion, whatsItDo(“WA”) prints “W”, whatsItDo(“WAT”) prints “WA”, whatsItDo(“WATC”) prints “WAT”, and finally, whatsItDo(“WATCH”) prints “WATC”, completing the recursive process.
Reflection:
- I think that the questions I got wrong were mainly due to not revising old concepts (such as recursion and how mathematical operations are carried out across different reference types) and not paying careful attention to each of the answer options. The best way to improve upon this would be to keep reviewing each unit until the exam and setting up a proper testing environment when practicing MCQs.