Score: 37/39 It was helpful to work on the quiz as a team. In the future, I need to work on timing as well as work on certain areas like 2D arrays.

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?

A 2 (int) (Math.random() 6)

B 2 (int) (Math.random() 7)

C (int) (Math.random() 6) + (int) (Math.random() 6)

D (int) (Math.random() * 13)

E 2 + (int) (Math.random() 6) + (int) (Math.random() 6)

I put A but this would lead to an integer between 0 and 10 inclusive. Instead the correct answer would be E which would simulate the value produced by rolling two number cubes.

Topic 2.9 - Using the Math Class

Question 22

Consider the following definition.

arrayQ22

Which of the following code segments produces the output 123456 ?

I chose E but this would be incorrect since the loop would iterate over the array in columns so it would print 142536. The correct answer would be A which would iterate over every row and then each column in that row to print out 12356.

Topic 8.2 - Traversing 2D Arrays