Expressions and Assignment Statements

AP Computer Science A· difficulty 3/5

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

What is printed?

  • A

    6 5

  • B

    5 6

  • C

    5 5

  • D

    6 6

    check_circle

Explanation

Pre-increment ++x increments x to 6 first, then assigns 6 to y.

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

Related questions