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. Cimpletd — The setCharAt method modifies characters at zero-based indices. Index 1 ('o' -> 'i') and index 7 ('e' -> 'd') transforms "Complete" into Cimpletd.
- A.
Complete
- B.
lomplede
- C.
Cimpletd
- 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.
Loading lesson…