OutputModerate2 marks
Give the output of the following Math functions: (i) Math.ceil(4.2) (ii) Math.abs(-4)
Topic: Math ceil and abs
Previous-year question practice database
Answer
Exam answer
(i) 5.0 (ii) 4
Explanation
(i) ceil() always rounds UP to the next whole number, however small the fraction, and it returns a double — so the answer is 5.0, not 5. The decimal point carries the mark. (ii) abs() removes the sign. Here the argument is the INT -4, and Math.abs() has an int version that returns an int, so the answer is 4 without a decimal point. Had the argument been -4.0, the answer would have been 4.0. That contrast — one answer with a decimal point and one without — is exactly what the question is testing.
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