Find the output of the following Java code line System.out.println(math.floor(-…

2011

Find the output of the following Java code line

System.out.println(math.floor(-7.4))

  1. A.

    -7

  2. B.

    -8.0

  3. C.

    -7.4

  4. D.

    -7.0

Attempted by 94 students.

Show answer & explanation

Correct answer: B

In Java, the Math.floor() method returns the nearest integer less than or equal to a given number, and the result is of type double. For a negative number like -7.4, “floor” means moving toward negative infinity, so the value becomes -8.0.

Explore the full course: Isro