What is the result?

Given:
12. String s = “abcdefgabc”;
13. char c = s.charAt(2);
14.
15. if (c == ‘c’)
16. s = s.replace(‘c’, ‘X’);
17. else if (c == ‘b’)
18. s = s.replace(‘b’, ‘O’);
19. else
20. s = s.replace(‘c’, ‘O’);
21. System.out.println(s);
What is the result?

Given:
12. String s = “abcdefgabc”;
13. char c = s.charAt(2);
14.
15. if (c == ‘c’)
16. s = s.replace(‘c’, ‘X’);
17. else if (c == ‘b’)
18. s = s.replace(‘b’, ‘O’);
19. else
20. s = s.replace(‘c’, ‘O’);
21. System.out.println(s);
What is the result?

A.
aOcdefgabc

B.
Compilation fails.

C.
abOdefgabc

D.
abXdefgabc

E.
abOdefgabO

F.
aOcdefgaOc

G.
abXdefgabX



Leave a Reply 0

Your email address will not be published. Required fields are marked *