?

AP® Computer Science Principles

Free Version

Upgrade subject to access all content

Moderate

Concatenating Strings

APCSP-KUECVX

Khadija is writing a piece of code that will ask the user for one letter at a time and concatenate all the letters together to form a word. Assume that the variable $x$ represents the letter that the user has input and the variable $y$ represents the word the user is forming.

Which of the following code segments would successfully concatenate the next letter with the word so far?

A

y ← x

B

y ← y + x

C

y + x ← y

D

y.concatenate(x)