Click to reopen instructions.

Mostly multiple choice. A few short answer. Move through the questions with the arrows next to n of 20 in the question box.

Questions of

What is the value of d?

double d = 13 / 5;

3.0

2.6

2.0

Nothing, this code won’t compile.

Which of these is the correct way to generate a random int between 0 and 100, inclusive?

(int) Math.random() * 100

(int) (Math.random() * 100)

(int) (Math.random() * 101)

(int) Math.random() * 101

What’s a good data type type to represent a measured mass in kilograms?

int

double

boolean

String

None of the above.

What’s a good data type type to represent the number of elephants in a memory? (I.e. a herd; “memory” is the collective noun for elephants.)

int

double

boolean

String

None of the above.

What’s a good data type type to represent the amount of money in your bank account?

int

double

boolean

String

None of the above.

What’s a good data type type to represent the number of atoms in the universe? Note the number of atoms in the universe is estimated to be somehere between 1078 and 1082 or, in base 2, between 2259 and 2266.

int

double

boolean

String

None of the above.

Which of these is the correct way to compute the fraction of seniors in a section as a double given the int variables numberOfSeniors and totalNumberOfStudents?

(double) numberOfSeniors / totalNumberOfStudents

(double) (numberOfSeniors / totalNumberOfStudents)

Which of these is would also work to compute the fraction of seniors in a section as a double given the int variables numberOfSeniors and totalNumberOfStudents?

1.0 * numberOfSeniors / totalNumberOfStudents

numberOfSeniors / totalNumberOfStudents * 1.0

Which of these is the correct way to convert the double variable fractionSeniors to a percentage in the range 0 to 100 rounded to the nearest integer.

(int) (fractionSeniors * 100)

(int) fractionSeniors * 100

(int) fractionSeniors * 100 + 0.5

(int) (fractionSeniors * 100 + 0.5)

(int) (fractionSeniors + 0.5 * 100)

(int) (fractionSeniors + 0.5) * 100

Which if these is the correct expression to get the value of the digit in the one’s place of n?

n / 10

n % 10

n * 10

n / 10.0

What is the value of this expression:

10.0 + 3 / 4 + 3.5

Hit enter to save answer.

What is the value of this expression:

2 / 4 * 3

Hit enter to save answer.

What is the value of this expression:

18 / 12 * 8.0

Hit enter to save answer.

What is the value of this expression:

7 - 2 % 3

Hit enter to save answer.

What is x after the following code runs:

int x = 0;
x += 1;
x -= 10;
x *= -3;
x %= 5;
x = x * 2;
x--;

Hit enter to save answer.

Same code as before except we don’t know the initial value of x. This time write out a single arithmetic expression, in terms of x that expresses the final value x would have after executing this code.

x += 1;
x -= 10;
x *= -3;
x %= 5;
x = x * 2;
x--;

Hit enter to save answer.

To compute the “z-score” of a value x from a population (for instance x might be the height of one person in a class) you compute the difference between x and the mean for the population and then divide that difference by the standard deviation of the population. Write an expression that computes a z-score given three double variables x, mean, and stddev.

Hit enter to save answer.

The following expressions are mathematically equivalent. Which of them will compute a result closer to the true mathematical value assuming a, b, and c are all int variables?

a * b / c

a / c * b

If totalMinutes is an int variable holding a number of minutes, write code to declare two intvariables hours and minutes representing the integer number of hours and minutes represented by the original number of minutes. For instance if minutes was 123 hours should be 2 and minutes should be 3.

Hit enter to save answer.

Which kind of monster are double values like?

Giant spiders

Orcs

Zombies

Poltergeists