String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 3/5

char c = 'X';
String s = "" + c + c;
System.out.println(s);

What is printed?

  • A

    XX

    check_circle
  • B

    X

  • C

    88

  • D

    176

Explanation

The empty string forces concatenation rather than int addition; 'X' is appended twice as a character.

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

Related questions