Question 431
int x = 3;
int y = 4;
System.out.println("score: " + x + y);
System.out.println("score: " + (x + y));
What is printed when the code segment executes?Main Solution
Answer
Answer: B. The + operator is left-associative and evaluates left to right. In the first line, "score: " + 3 is a String, so the next + 4 is string concatenation, producing "score: 34". In the second line, parentheses force the integer addition 3 + 4 = 7 to happen first, so the concatenated output is "score: 7".
Answer: Correct: B
A
score: 7
score: 7B
score: 34
score: 7C
score: 7
score: 34D
score: 34
score: 34Answer images

