K

Kirti • 10.45K Points
Tutor II

Q. What is the output of the following code snippet?

Code:
String s1 = “Hello”;
String s2 = sA)replace(‘l’, ‘z’);
System.out.println(s2);
  • (A) Hezzo
  • (B) Helzo
  • (C) H
  • (D) Error
  • Correct Answer - Option(A)
  • Views: 179
  • Filed under category JAVA

Explanation by: Kirti
The replace method in Java returns a new string that is the original string with all occurrences of a specified character replaced by another character. In this case, sA)replace(‘l’, ‘z’) returns “Hezzo”.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics