Math Class MCQ Practice

Question 1 of 10

A greenhouse sensor reports -7 degrees relative to target. What value does adj hold?

int adj = Math.abs(-7);
  1. A. -7
  2. B. 7.0
  3. C. 7
  4. D. 0

Question 2 of 10

A square tray has area 36. What value does edge hold?

double edge = Math.sqrt(36);
  1. A. 6
  2. B. 18.0
  3. C. 6.0
  4. D. 36.0

Question 3 of 10

What value does volume hold?

double volume = Math.pow(3, 2);
  1. A. 6.0
  2. B. 9
  3. C. 8.0
  4. D. 9.0

Question 4 of 10

What value does clipped hold?

int clipped = (int) Math.pow(2, 3);
  1. A. 8.0
  2. B. 9
  3. C. 8
  4. D. 6

Question 5 of 10

A rain simulation uses Math.random() with no scaling. Which statement is true?

  1. A. The result can be 1.0.
  2. B. The result can be 0.0 but cannot be 1.0.
  3. C. The result is an int 0 or 1.
  4. D. The result is always greater than 0.5.

Question 6 of 10

Which integers can (int)(Math.random() * 1) produce?

  1. A. 0 only
  2. B. 0 and 1
  3. C. 1 only
  4. D. 0.0 only as a double

Question 7 of 10

A tray ID must be an int from 18 through 22 inclusive. Which expression is correct?

  1. A. (int) (Math.random() * 22) + 18
  2. B. (int) (Math.random() * 5) + 18
  3. C. (int) (Math.random() * 5) + 22
  4. D. (int) (Math.random() * 18) + 5

Question 8 of 10

A supplied Math.random() value is 0.25. What value does slot hold?

int slot = (int) (0.25 * 8);
  1. A. 2.0
  2. B. 3
  3. C. 2
  4. D. 0

Question 9 of 10

Which expression produces a double in [0.0, 8.0) with no added shift?

  1. A. Math.random() + 8
  2. B. Math.random() * 8
  3. C. (int) (Math.random() * 8)
  4. D. Math.random() * 8 + 1

Question 10 of 10

What value does mix hold?

double mix = Math.pow(2, 3) - Math.sqrt(9);
  1. A. 5
  2. B. 5.0
  3. C. 1.0
  4. D. 8.0