Discussion Forum : Introduction To Methods And Streams
Question -


What is the output of this program?


class output {
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello World");
s1.insert(6 , "Good ");
System.out.println(s1);
}
}
Options:
A .  HelloGoodWorld
B .  HellGoodoWorld
C .  HellGood oWorld
D .  Hello Good World
Answer: Option D

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:
$ javac output.java
$ java output
Hello Good World




Was this answer helpful ?
Next Question
Submit Your Solution hear:

Your email address will not be published. Required fields are marked *