Expressions and Assignment Statements

AP Computer Science A· difficulty 2/5

int x = 5;
int y = x++;
System.out.println(x + " " + y);

What is printed?

  • A

    6 5

    check_circle
  • B

    5 5

  • C

    6 6

  • D

    5 6

Explanation

Post-increment x++ assigns the old value 5 to y, then increments x to 6.

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

Related questions