What will be the output of the program? Public class test 2 { Public static…

2022

What will be the output of the program? Public class test 2 { Public static void main (String [ ] args) { StringBuffer S1 = new StringBuffer("Complete"); S1.setCharAt(1, 'i'); S1.setCharAt(7, 'd'); System.out.println(S1); } }

Answer: C. CimpletdThe setCharAt method modifies characters at zero-based indices. Index 1 ('o' -> 'i') and index 7 ('e' -> 'd') transforms "Complete" into Cimpletd.

  1. A.

    Complete

  2. B.

    lomplede

  3. C.

    Cimpletd

  4. D.

    Coipletd

Attempted by 352 students.

Show answer & explanation

Correct answer: C

The setCharAt method modifies characters at zero-based indices. Index 1 ('o' -> 'i') and index 7 ('e' -> 'd') transforms "Complete" into Cimpletd.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs

Loading lesson…