Menu
Topics Index
...
`

Insert 2233


If you need explanation Read this topic

If you need Answer Take test on this topic

Insert 2233
What will be the output of the following program?
public class AllInsert {
    public static void main(String args[]) {
        StringBuffer s = new StringBuffer("I love my mother.");
        char[] c1 = new char[]{'H', 'e', 'l', 'l', 'o'};
        s.insert(6, c1);
        double d = 5.0;
        s.insert(6, d);
        float f = 7.0f;
        s.insert(5, f);
        int i = 5;
        s.insert(6, i);
        long l = 10;
        s.insert(7, l);
        String str = "Old";
        s.insert(8, str);
        System.out.println(s);
    }
}

A. I lov751Old.0e5.0Hello my mother.
B. I lov751Old0.0e5.0Hello my mother.
C. I lov751Old0.0e5.Hello my mother.
D. Compilation Error or Runtime Error
Topic: Java StringBuffer insert() Method With Example

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

option B
as character array is insertes in s[6]
and updated string buffer double is inserted @ a[6] it comes before "Hello" character array
flaot comes at a[5] and this is iteratively continued

Posted by Sasikanth Sharma    2014-05-21 09:02:32


as f and d are float and double they print as 5.0 and 7.0 as they are converted into string "." is also considered as character of string

Posted by Sasikanth Sharma    2014-05-21 09:04:53


ans b. c1arr insertd in s[6] place .d is insertd between e and H,f is insertd after v,i is insertd in6th place betwn 7 and ".",l is insertd btwen 5 and ".",str insertd btwn 1 and 0.

Posted by Maheshwari Natarajan    2014-05-21 09:41:05


No winner for this dose :( . Correct option is 'B' . Maheshwari Natarajan was already won in this week.

Posted by Merit Campus    2014-05-22 05:48:01


© meritcampus 2019

All Rights Reserved.

Open In App