MCQ - 2015 Corrections

MCQ

Score 34/39. Score was OK but more silly mistakes were made than I would’ve liked.

Q9

A pair of number cubes is used in a game of chance. Each number cube has six sides, numbered from 1 to 6, inclusive, and there is an equal probability for each of the numbers to appear on the top side (indicating the cube’s value) when the number cube is rolled. The following incomplete statement appears in a program that computes the sum of the values produced by rolling two number cubes.

int sum = / * missing code * / ;

Which of the following replacements for /* missing code */ would best simulate the value produced as a result of rolling two number cubes? Responses Wrong Answer: (int) (Math.random() * 6) + (int) (Math.random() * 6) Correct Answer: 2 + (int) (Math.random() * 6) + (int) (Math.random() * 6)

The Math.random() gives a random number from 0 to 1. Multiplying this by 6 gives a random number of 0 to 6, and casting as an integer gives from 0 to 5. Therefore, two must be added to give a simulation of two dice.

Mistake: The number is not already an integer, and when casted the output is never 6.

Q21

Consider the following recursive method.

What is printed as a result of the call whatsItDo(“WATCH”) ?

public static void whatsItDo(String str) {
    int len = str.length();
    if (len > 1) {
        String temp = str.substring(0, len - 1);
        System.out.println(temp);
        whatsItDo(temp);
    }
}

whatsItDo("WATCH")
WATC
WAT
WA
W

As visible from code above, correct answer is WATC, WAT, WA, W. The function recursively calls itself to remove the last letter of the string each time before printing it out.

MISTAKE: I thought the function printed the string first, before removing the last letter.

Q22

Consider the following definition. Which of the following code segments produces the output 123456?

Correct Answer:

for (int[] row : numbers) {
    for (int n : row) {
        System.out.print(n);
    }
}
123456

This one was quite obvious, misclick.

MISTAKE: Did not double check selected correct answers

Q26

Consider the following two methods, which appear within a single class. What is printed as a result of the call start()?

Image 12

Wrong Answer: 0 0 0 0 0 0 black Correct Answer: 1 2 3 4 5 6 blackboard

MISTAKE: I did not see the arr = new int[5];. I knew that parameters in java are passed using call by value and are references, and assumed that the parameter values were updated without seeing this line, which sets a new array to avoid modifying the old one.

Q27

Directions: Select the choice that best fits each statement. The following question(s) refer to the following information.

Consider the following sort method. This method correctly sorts the elements of array data into increasing order.

Assume that sort is called with the array {6, 3, 2, 5, 4, 1}. What will the value of data be after three passes of the outer loop (i.e., when j = 2 at the point indicated by / * End of outer loop * /) ?

Image 13

Wrong Answer: {1, 2, 3, 4, 5, 6} Correct Answer: {1, 2, 3, 5, 4, 6}

MISTAKE: Did not read the after three passes of the outer loop and instead selected the option that results from completing all passes.

FRQ

Tangibles TBA - Under Construction

Comments

You are seeing this because your Disqus shortname is not properly set. To configure Disqus, you should edit your _config.yml to include either a disqus.shortname variable.

If you do not wish to use Disqus, override the comments.html partial for this theme.