Computer Applications
The output of the following code is:
System.out.println(Math.ceil(6.4) + Math.floor(-1-2));
- 3.0
- 4
- 3
- 4.0
Java
Java Math Lib Methods
ICSE Sp 2025
22 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
ceilmethod rounds a number up to the nearest integer. Math.ceil(6.4)→7.0(asceilreturns adouble).
Step 2: Evaluate -1 - 2
-1 - 2 = -3
Step 3: Evaluate Math.floor(-3)
Math.floor(-3): Thefloormethod rounds a number down to the nearest integer.Math.floor(-3)→-3.0(asflooralso returns adouble).
Step 4: Add the Results
Math.ceil(6.4)+Math.floor(-3)→7.0 + (-3.0)- Result =
4.0
Answered By
11 Likes
Related Questions
Identify the operator that gets the highest precedence while evaluating the given expression:
a + b % c * d - e
- +
- %
- -
- *
Which of the following is a valid java keyword?
- If
- BOOLEAN
- static
- Switch
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
Which of the following is not true with regards to a switch statement?
- checks for an equality between the input and the case labels
- supports floating point constants
- break is used to exit from the switch block
- case labels are unique