Casting and Range of Variables MCQ Practice

Question 1 of 10

A pedometer copies a whole-step count into a double for later averaging. What value does pace hold?

int steps = 48;
double pace = steps;
  1. A. The int 48 with no conversion
  2. B. 48.0
  3. C. The assignment does not compile.
  4. D. 0.48

Question 2 of 10

A bakery program truncates each measured cup before combining them. What value does mix hold?

int mix = (int) 9.6 + (int) 3.9;
  1. A. 13
  2. B. 13.5
  3. C. 12
  4. D. 14

Question 3 of 10

A freezer probe reads just below zero. What value does display hold?

double probe = -0.4;
int display = (int) probe;
  1. A. -1
  2. B. 0
  3. C. -0.4
  4. D. 1

Question 4 of 10

Which statement is true of this fragment?

double mix = 20;
int scoops = mix / 3;
  1. A. scoops stores 6 because integer division occurs.
  2. B. The assignment does not compile because mix / 3 has type double.
  3. C. scoops stores 7 after rounding to the nearest integer.
  4. D. scoops stores 6.666666666666667.

Question 5 of 10

A cold-storage counter is already at the minimum int. What value does cold hold after this update?

int cold = Integer.MIN_VALUE;
cold -= 5;
  1. A. -2147483653
  2. B. The program throws ArithmeticException.
  3. C. 2147483643
  4. D. -2147483648

Question 6 of 10

A mural is 46341 tiles wide and 46341 tiles tall. The mathematical product is 2147488281. Which statement is true?

int wide = 46341;
int tall = 46341;
int tiles = wide * tall;
  1. A. tiles is 2147488281.
  2. B. tiles is a wrapped int, not 2147488281, because the product exceeds Integer.MAX_VALUE.
  3. C. tiles is 2147483647 because the value saturates at the maximum.
  4. D. The multiplication throws ArithmeticException.

Question 7 of 10

Which statement about the Java int range is correct?

  1. A. Integer.MAX_VALUE is 2147483648.
  2. B. Integer.MIN_VALUE is -2147483648 and Integer.MAX_VALUE is 2147483647.
  3. C. int can represent every mathematical integer.
  4. D. Crossing either bound throws ArithmeticException.

Question 8 of 10

A warehouse wants the updated stock qty + inbound - outbound. Which single operation already overflows as int arithmetic?

int qty = 1400000000;
int inbound = 900000000;
int outbound = 200000000;
  1. A. qty - outbound
  2. B. inbound - outbound
  3. C. qty + inbound
  4. D. outbound + inbound

Question 9 of 10

A program prints a double with one decimal place and the output looks like 0.3, but a later == comparison with 0.3 is false. Which statement is accurate?

  1. A. A neatly printed value proves the stored double is exact.
  2. B. Display formatting can hide a small stored round-off error.
  3. C. The == operator always throws when used with double.
  4. D. Printing a double converts it to int.

Question 10 of 10

Which row describes floating-point round-off rather than int overflow?

Row Situation
K Integer.MAX_VALUE + 1
L Storing 1.0 / 3.0 as a repeating binary approximation
M 2000000000 + 2000000000
N Integer.MIN_VALUE - 1
  1. A. Row K
  2. B. Row L
  3. C. Row M
  4. D. Row N