OutputModerate2 marks
State the data type and value of res after the following is executed: char ch = '9'; res = Character.isDigit(ch);
Topic: isDigit() and return types
Previous-year question practice database
Answer
Exam answer
Data type: boolean Value: true
Explanation
Character.isDigit() asks a yes-or-no question, so it returns boolean. The character '9' IS a digit, so the value is true. Note the subtlety worth mentioning: '9' in single quotes is the CHARACTER nine, whose ASCII code is 57, not the number 9. isDigit() correctly recognises it as a digit character. Group the Character methods by return type: the is... methods return boolean, the to... methods return char.
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