Oracle
1Z0-803 · Question #235
Given: public class String1 { public static void main(String[] args) { String s = "123"; if (s.length() >2) s.concat("456"); for(int x = 0; x <3; x++) s += "x"; System.out.println(s); } } What is the
The correct answer is B. 123xxx. The if clause is not applied. Note: Syntax of if-statement: if ( Statement ) {
Working with Selected Classes from the Java API
Question
Given:
public class String1 { public static void main(String[] args) { String s = "123"; if (s.length() >2) s.concat("456"); for(int x = 0; x <3; x++) s += "x"; System.out.println(s); } } What is the result?
Options
- A123
- B123xxx
- C123456
- D123456xxx
- ECompilation fails
How the community answered
(48 responses)- A15% (7)
- B71% (34)
- C2% (1)
- D4% (2)
- E8% (4)
Explanation
The if clause is not applied. Note: Syntax of if-statement: if ( Statement ) {
Topics
#String immutability#String concatenation#concat()#for loop
Community Discussion
No community discussion yet for this question.