Casting and Ranges of Variables

AP Computer Science A· difficulty 3/5

int a = 9;
int b = 4;
double r = (double)(a / b);
System.out.println(r);

What is printed?

  • A

    2.0

    check_circle
  • B

    2.25

  • C

    2

  • D

    2.5

Explanation

The cast applies after the int division a / b which is 2; converting 2 to double gives 2.0.

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

Related questions