String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 2/5

String s = "Score: ";
int n = 5;
System.out.println(s + 3 + n);

What does this print?

  • A

    Score: 35

    check_circle
  • B

    Score: 8

  • C

    Score: 53

  • D

    Compile error

Explanation

Left-to-right + with a String produces String concatenation: "Score: " + 3 = "Score: 3", then + 5 yields "Score: 35".

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

Related questions