132k views
5 votes
Given the following StringBuilder object named cn, which statement adds -9326 to it?

StringBuilder cn = new StringBuilder("2375-3847-8455");
a. cn.Append(-9326);
b. cn.Append("-9326");
c. cn.Add(-9326);
d. cn.Add("-9326");

User Mppf
by
9.4k points

1 Answer

5 votes

Final answer:

To add "-9326" to a StringBuilder object named cn, the correct method is cn.Append("-9326"); thus option b is the correct answer.

Step-by-step explanation:

The student has asked how to add "-9326" to a StringBuilder object named cn that already contains the string "2375-3847-8455". The correct statement to use for appending a string to a StringBuilder object in Java is the append() method. Therefore, the correct answer is choice b: cn.Append("-9326");. This will properly add the string "-9326" to the end of the existing StringBuilder content.

User Rob Cole
by
7.6k points