Computer Applications

Sham was asked to encode a string S, by replacing the letter E with #. Select the appropriate statement:

  1. S.replace('#','E')
  2. S.replace('E')
  3. S.replace('E', '#')
  4. S.replace('#')

Java String Handling

5 Likes

Answer

S.replace('E', '#')

Reason — The replace() method in Java is used to replace characters in a string. The correct syntax is S.replace(oldChar, newChar). Since the question asks to replace the letter E with #, we use S.replace('E', '#').

Answered By

5 Likes


Related Questions