MCQModerate1 mark
1
Choose the correct answers to the questions from the given options. (Do not copy the questions, write only the correct answers.)
Which of the following mathematical methods returns only an integer?
Topic: Math methods and return types
Previous-year question practice database
Try it
Pick an option and check your answer. The full worked answer is below either way.
Answer
Exam answer
(d) Math.round(n).
Explanation
The trap is that ceil() and floor() give whole NUMBERS but return them as doubles — Math.ceil(5.4) is 6.0, not 6. Only Math.round() returns an integral type (a long for a double argument, an int for a float). sqrt() returns a double as well. Read such questions as asking about the return TYPE, not the appearance of the value.
In words
Math.round(n).
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