Oracle
1Z0-851 · Question #201
Given: 01. public class TestString3 { 02. public static void main(String[] args) { 03. // insert code here 04. System.out.println(s); 05. } 06. } Which two code fragments, inserted independently at…
The correct answer is B. StringBuffer s = new StringBuffer("123456789"); E. substring(3,6).delete(1,3).insert(1, "24"). See the full explanation below for the reasoning.
Question
Given: 01. public class TestString3 { 02. public static void main(String[] args) { 03. // insert code here 04. System.out.println(s); 05. } 06. } Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)
Options
- AString s = "123456789"; s = (s-"123").replace(1,3,"24") - "89";
- BStringBuffer s = new StringBuffer("123456789");
- Cdelete(0,3).replace(1,3,"24").delete(4,6);
- DStringBuffer s = new StringBuffer("123456789");
- Esubstring(3,6).delete(1,3).insert(1, "24");
- FStringBuilder s = new StringBuilder("123456789");
- Gsubstring(3,6).delete(1,2).insert(1, "24");
- HStringBuilder s = new StringBuilder("123456789");
How the community answered
(28 responses)- A4% (1)
- B71% (20)
- D14% (4)
- G7% (2)
- H4% (1)
Community Discussion
No community discussion yet for this question.