What will be the output of the following Java code? [code] class output { public static void main(String args[])

Vy Bùi

New member
What will be the output of the following Java code?
Code:
    class output 
    {
        public static void main(String args[])
        {
           StringBuffer s1 = new StringBuffer("Hello World");
           s1.insert(6 , "Good ");
           System.out.println(s1);
        }
   }
A. HelloGoodWorld
B. HellGoodoWorld
C. HellGood oWorld
D. Hello Good World
 
Answer: d
Explanation: The insert() method inserts one string into another. It is overloaded to accept values of all simple types, plus String and Objects. Sting is inserted into invoking object at specified position. “Good ” is inserted in “Hello World” T index 6 giving “Hello Good World”.
output:
Code:
$ javac output.java
$ java output 
Hello Good World
 

Tìm kiếm

Back
Top