Short answerModerate2 marks
Write the return type of the following library functions: (i) isLetterOrDigit(char) (ii) replace(char, char)
Topic: Return types of library functions
Previous-year question practice database
Answer
Exam answer
(i) boolean (ii) String
Explanation
(i) Character.isLetterOrDigit() asks whether a character is a letter or a digit — a yes-or-no question, so boolean. Every is... method of the Character class behaves the same way. (ii) replace() produces a NEW string with every occurrence of one character swapped for another, and returns it as a String. Note that the original string is unchanged, because Strings are immutable — which is why the method must return something rather than modify in place.
More from Library Classes
What is the output of the statement Math.pow(36, 6/5);?2026The output of the statement:
System.out.println(Character.toUpperCase('b') + 2); is:2026What is the type of parameter to be given for the method parseInt()?2026Write the Java expression to find the sum of cube root of x and the absolute value of y.2026Character class methods are found in the package called:2025The output of Math.max(-7, Math.min(-5, -4)) is2025