0 votes
in JAVA by

 What will be the output of the following program?

public class Test2 {  

    public static void main(String[] args) {  

        StringBuffer s1 = new StringBuffer("Complete");  

        s1.setCharAt(1,'i');  

        s1.setCharAt(7,'d');  

        System.out.println(s1);  

     }  

 }  

a) Complete

b) Iomplede

c) Cimpletd

d) Coipletd

1 Answer

0 votes
by

(c) Cimpletd

Reason: In the above code snippet, we have passed a string with value "Complete" and set character "i" and "d" at the index position 1 and 7, respectively. According to the string "Complete," "o" is at position 1, and "e" is at the position 7. The setChar() method is used to replace the original string values with the new one. Hence, the "o" and "e" are replaced by the characters "i" and "d," respectively, which results in "Cimpletd."

Related questions

0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
...