GIAC
GSSP-JAVA · Question #235
Given a code of a class named PrintString that prints a string. 1. public class PrintString{ 2. public static void main(String args[]){ 3. /insert code here / 4. / insert code here / 5…
The correct answer is A. StringBuilder str= new StringBuilder("123456789"); B. StringBuffer str= new StringBuffer("123456789"). See the full explanation below for the reasoning.
Question
Given a code of a class named PrintString that prints a string. 1. public class PrintString{ 2. public static void main(String args[]){ 3. /*insert code here / 4. / insert code here */ 5. System.out.println(str); 6. } 7. } Which of the following code fragments can be inserted in the class PrintString to print the output "4247"? Each correct answer represents a complete solution. Choose all that apply.
Options
- AStringBuilder str= new StringBuilder("123456789");
- BStringBuffer str= new StringBuffer("123456789");
- CStringBuffer str=new StringBuffer("123456789");
- DStringBuilder str= new StringBuilder("123456789");
- EString str="123456789";
How the community answered
(26 responses)- A77% (20)
- C4% (1)
- D12% (3)
- E8% (2)
Community Discussion
No community discussion yet for this question.