String Concatenation With The Plus Operator
In the code segment below, which statement correctly concatenates the String variables s1 and s2 with a space between them? The statement must use the + operator for concatenation and assign the result to a new String variable named result.
public class StringConcat {
public static void main(String[] args) {
String s1 = "AP";
String s2 = "Computer";
// Missing statement
System.out.println(result);
}
}
A
String result = s1.concat(" ").concat(s2);
B
String result = s1 + s2;
C
String result = s1.concat(s2);
D
String result = s1 + " " + s2;
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 2 | 3 | 0m 00s | 190 |
| #2 | y.seong2027 | 2 | 2 | 0m 33s | 167 |
| #3 | jeonsaw1723 | 2 | 2 | 0m 38s | 162 |
| #4 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #5 | lsj08030922 | 1 | 1 | 0m 19s | 81 |
| #6 | patrickmeijer009 | 1 | 2 | 0m 17s | 73 |
| #7 | ananyetyagi | 1 | 1 | 0m 29s | 71 |
| #8 | chunxiangxu.cxu | 2 | 3 | 2m 17s | 53 |
| #9 | varunrajaram1 | 1 | 1 | 1m 00s | 40 |
| #10 | areeshaabdulrasheed | 0 | 1 | 0m 14s | -24 |
Items per page:
10
1 – 10 of 15
APFIVE