Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

 FileShortTitle:Mock Question 4-5 FileLongTitle:OCA Mock Question Core Java APIs 4-5 FileTag:Mock Question FileID:longtutorial/Java/OCA_Java_SE_8_Core_Java_APIs/Q4-5. xml===SectionShortTitle:Question SectionLongTitle:Question SectionContent:

 <p>Which of the following can replace line 2 to print"DCBA"?(Choose all that apply)</p><myPreCode>1:StringBuilder v=new StringBuilder("ABCD");2: // INSERT CODE HERE 
 3:System.out.println(v);</myPreCode>

 <ol type="A"><li>v.reverse();</li><li>v.append("CBA$").substring(0,4);</li><li>v.append("CBA$").delete(0,3).deleteCharAt(v.length()-1);</li><li>v.append("CBA$").delete(0,3).deleteCharAt(v.length());</li><li>None of the above.</li>

 </ol>===SectionShortTitle:Answer SectionLongTitle:Answer SectionContent:

 <input type='button'class='btn btn-primary'data-toggle='collapse'data-target='#answer'value='Click for the answer'/><br/><br/><div id='answer'class='collapse out'><p>A,C.</p></div>===SectionShortTitle:Note SectionLongTitle:Note SectionContent:

 <p>The reverse()method can do the trick.</p>

 <p>Option C creates the value"ABCDCBA$".Then it removes the first three characters,resulting in"DCBA$".Finally,it removes the last character,resulting in"DCBA".</p><myPreCode>
 public class Main {
public static void main(String[] argv){
   StringBuilder v = new StringBuilder("ABCD"); 
   v.reverse();  
   System.out.println(v); 
   
}
 }</myPreCode>===SectionShortTitle:Example SectionLongTitle:Example SectionContent: