• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
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");  






a) Complete

b) Iomplede

c) Cimpletd

d) Coipletd

1 Answer

0 votes

(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 in JAVA by Robindeniel
0 votes
asked Apr 9 in JAVA by Robindeniel