182k views
2 votes
Consider the statements below:

String a = ""JAVA: "";
String b = ""How to "";
String c = ""Program"";
Which of the statements below will create the String r1 = ""JAVA: How to Program""?
a. String r1 = ( (a));
b. String r1 = ( (c));
c. String r1 = ( (a));
d. String r1 = ( (b));"

1 Answer

4 votes

Final answer:

To concatenate the Strings 'JAVA: ', 'How to ', and 'Program' into 'JAVA: How to Program', you would need to use the expression 'a + b + c'. The provided options are not correct as they don't combine all three variables.

Step-by-step explanation:

To create the String r1 = "JAVA: How to Program" using the provided variables a, b, and c, we will need to concatenate them in the correct order. The variables a, b, and c already contain parts of the desired outcome. To get r1, you must concatenate the Strings in the order of variable a, then b, and then c. Therefore, the code that accomplishes this is String r1 = a + b + c;. None of the provided options are correct as they either reference only one variable or are syntax errors.

User Technoweenie
by
8.1k points