201k views
2 votes
You are given the String object declarations:

String one = ""end"", two = ""file"", newStr;
Which one of the statements below will result in newStr to have the value ""end-of-file""?
a) newStr = one + '-' + ""of"" + '-' + two;
b) newStr = one + ""-"" + ""of"" + ""-""+ two;
c) newStr = one + -of- + two;
d) newStr = ""one""; newStr += ""-of-""; newStr += ""two"";
e) All of the above

1 Answer

5 votes

Final answer:

The correct statement to result in newStr having the value "end-of-file" is option b) newStr = one + "-" + "of" + "-"+ two.

Step-by-step explanation:

The correct statement to result in newStr having the value "end-of-file" is option b) newStr = one + "-" + "of" + "-"+ two. This statement uses the concatenation operator (+) to combine the values of the String variables one, "-", "of", "-", and two in the correct order to create the desired value. The other options either have incorrect syntax or do not create the required value.

User Byran Zaugg
by
8.0k points