OutputEasy2 marks
Give the output of the following Character class methods: (a) Character.toUpperCase('a') (b) Character.isLetterOrDigit('#')
Topic: Character class methods
Previous-year question practice database
Answer
Exam answer
(a) A (b) false
Explanation
(a) toUpperCase() converts a lowercase letter to its uppercase form and returns a char, so 'a' becomes A. Had the argument already been uppercase or not a letter at all, it would be returned unchanged. (b) isLetterOrDigit() returns a boolean. The character # is neither a letter nor a digit — it is a special character — so the answer is false, printed in lower case as Java prints all booleans. Note the pattern in the marks: one method returns a char, the other a boolean. Questions on this chapter almost always test whether you know the RETURN TYPE as well as the effect.
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