Output Questions for Class 10 ICSE Computer Applications

Predict the output of the following Java program snippet:

System.out.println(Math.floor(-4.7));

Java

Java Math Lib Methods

ICSE 2018

26 Likes

Answer

-5.0

Working

Math.floor method returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. As -5.0 is the largest mathematical integer less than -4.7 so it is the output. Note that -4.7 is a negative number so the largest integer less than -4.7 is -5.0 and not -4.0.

Answered By

14 Likes