Casting and Ranges of Variables

AP Computer Science A· difficulty 3/5

double d = 9.7;
int i = (int) d;
System.out.println(i);

What is printed?

  • A

    9

    check_circle
  • B

    10

  • C

    9.7

  • D

    9.0

Explanation

Casting a double to an int truncates the decimal portion (it does not round), so 9.7 becomes 9.

Want 10 more like this — adaptive to your weak spots?

Related questions