KnowledgeBoat Logo

Computer Applications

The output of the following code is:

System.out.println(Math.ceil(6.4) + Math.floor(-1-2));
  1. 3.0
  2. 4
  3. 3
  4. 4.0

Java

Java Math Lib Methods

ICSE Sp 2025

4 Likes

Answer

4.0

Reason — Let's evaluate the expression step by step:

System.out.println(Math.ceil(6.4) + Math.floor(-1 - 2));

Step 1: Evaluate Math.ceil(6.4)

  • The ceil method rounds a number up to the nearest integer.
  • Math.ceil(6.4)7.0 (as ceil returns a double).

Step 2: Evaluate -1 - 2

  • -1 - 2 = -3

Step 3: Evaluate Math.floor(-3)

  • Math.floor(-3): The floor method rounds a number down to the nearest integer.
  • Math.floor(-3)-3.0 (as floor also returns a double).

Step 4: Add the Results

  • Math.ceil(6.4) + Math.floor(-3)7.0 + (-3.0)
  • Result = 4.0

Answered By

3 Likes


Related Questions