OutputHard2 marks
Give the output of the following: (i) Math.floor(-4.7) (ii) Math.ceil(3.4) + Math.pow(2, 3)
Topic: Math floor, ceil and pow
Previous-year question practice database
Answer
Exam answer
(i) -5.0 (ii) 12.0
Explanation
(i) floor() always rounds DOWN, meaning towards the smaller value. With negatives that means AWAY from zero: -4.7 becomes -5.0, not -4.0. This is the single commonest error in Math questions — picture the number line, where -5 lies below -4.7. (ii) ceil(3.4) rounds up to 4.0, and pow(2, 3) is 2 cubed, 8.0. Their sum is 12.0. Both answers must carry the decimal point, since all three methods return doubles.
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