Expressions and Assignment Statements

AP Computer Science A· difficulty 3/5

int x = 5;
double y = 2.0;
System.out.println(x / y);

What is printed?

  • A

    2.5

    check_circle
  • B

    2

  • C

    2.0

  • D

    3

Explanation

When one operand is a double, the other int is promoted to double; 5 / 2.0 yields 2.5.

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

Related questions