Score: 32/39

2015 practice score

Notes/Corrections:

Question 9:

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?

Comments:

We were debating between:

C: (int) (Math.random() * 6) + (int) (Math.random() * 6)
E: 2 + (int) (Math.random() * 6) + (int) (Math.random() * 6)

Our team was uncertain if typecasting a double into an int rounds down, which after looking it up we found that it did, meaning we would need to add 2 to our Math.random() runs

So, the correct answer is E.

Question 12:

Assume that x and y are boolean variables and have been properly initialized.

An expression reads as follows: (x && y) && !(x || y)

Which of the following best describes the result of evaluating the expression above?

Comments:

I was at first unsure of how to distribute a NOT to an or, then Toby conceptually explained how that would turn into a not x and not y, or !x && !y

Question 12:

Consider the following code segment.

int x = 1;
while ( /* condition */ )
{
    if (x % 2)
    {
        System.out.print(x + " ");
    }
    x = x + 2;
}

The following conditions have been proposed to replace /* condition */ in the code segment.

  1. x < 0
  2. x <= 1
  3. x < 10

For which of the conditions will nothing be printed?

Comments:

I chose I and II, because I did not realize that x = x + 2 would guarantee that x is always odd because it starts at 1, meaning that it wouldn’t print anything for all three options.

Question 22

Consider the following definition.

int[][] numbers = [[1, 2, 3],
                [4, 5, 6]];

note: these are supposed to be curly not square braces, used curly so that it wouldnt cause liquid issues.

Which of the following code segments produces the output 123456 ?

Comments

Our team was debating between:

A:

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

E:

for (int c = 0; c < numbers[0].length; c ++) {
    for (int r = 0; r < numbers.length; r ++) {
        System.out.print(numbers[r][c])
    }
}

However, after realizing that option E would print them in columns then rows order (142536), we saw that A was the correct answer.

Question 27

mcq

Comments

I don’t know why but my brain thought the smallest element in selection goes to the end instead of swapping with the min.

Question 30

30

Comments

option I uses 3 if statements and not else ifs, meaning it would do all of them

Questions 35-38

I let Adi guess random ones for me because I got bored of doing the actual test

Comments

Most of these are just tracing through iterations and loops, literally can’t get them wrong if you write it down