Computer Applications
Sham was asked to encode a string S, by replacing the letter E with #. Select the appropriate statement:
- S.replace('#','E')
- S.replace('E')
- S.replace('E', '#')
- S.replace('#')
Java String Handling
3 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
1 Like
Related Questions
Raj was asked to accept the phone number which has 10 digits, using the appropriate method of Scanner class. Which of the following statement he must choose?
- Ob.nextInt()
- Ob.nextDouble()
- Ob.nextLong()
- Ob.next().chatAt(0)
Raj wanted to count the number of digits in a given number without using a loop. Which of the following statements is correct to perform the above?
- String.valueOf(n).length()
- Integer.parseInt(n).length()
- n.length()
- All the above
When the String
mis compared ton, the result obtained is greater than zero. Which of the following is true?mcomes before n in the dictionary.ncomes beforemin the dictionary.mandnare equal.mandnhave the same length.
Which of the following String methods has integer argument?
(i) length
(ii) substring
(iii) indexOf
(iv) charAt- Only (ii)
- (i) and (iv)
- (ii) and (iv)
- (iii) and (iii)