Java | Functions | Question 8

Predict the output of the following program.

filter_none

edit
close

play_arrow

link
brightness_4
code

class Test
{
    public static void main(String[] args)
    {
        StringBuffer a = new StringBuffer("geeks");
        StringBuffer b = new StringBuffer("forgeeks");
        a.delete(1,3);
        a.append(b);
        System.out.println(a);
    }
}

chevron_right


(A) gsforgeeks
(B) gksforgeeks
(C) geksforgeeks
(D) Compilation error


Answer: (B)

Explanation:
delete(x, y) function deletes the elements from the string at position ‘x’ to position ‘y-1’.
append() function concatenates the second string to the first string.


Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.