(vi) The output of the following code is:
System.out.println(Math.ceil(6.4)
+Math.floor(-1-2));
(a) 3.0
(b) 4
(c) 3
(d) 4.0
Solution
Math.ceil(6.4):
Math.ceil() returns the smallest integer greater than or equal to the given number.
Math.ceil(6.4) will give 7.0.
Math.floor(-1 - 2):
First, evaluate -1 - 2 which gives -3.
Math.floor() returns the largest integer less than or equal to the given number.
Math.floor(-3) will give -3.0.
Adding the results:
7.0 + (-3.0) = 4.0
(d) 4.0