double x=2.9,y=2.5
System.out.println(Math.min(Math.floor(x),y));
System.out.println(Math.max(Math.ceil(x),y));
2
Answers
Answered by
4
Output -
2
3
Explanation -
(1) Math.floor(x) will return the greatest integer than is less than or equal to the value of x i.e. 2.9 so result will be 2 and Math.min() will choose the smaller between 2 and 2.5 that is obviously 2.
(2) Math.ceil(x) will return the smallest integer than is greater than or equal to the value of x i.e. 2.9 so result will be 3 and Math.max() will choose the greater between 3 and 2.5 that is obviously 3.
Answered by
2
Question:-
- Write the output of the following code segment.
Output:-
2.0
3.0
Steps:-
Given code,
double x=2.9, y=2.5;
System.out.println(Math.min(Math.floor(x), y)) ;
System.out.println(Math.max(Math.ceil(x), y)) ;
Now, we will calculate,
Math.min(Math.floor(x),y)
=Math.min(2.0,2.5)
=2.0
Also,
Math.max(Math.ceil(x),y)
=Math.max(3.0,2.5)
=3.0
Note:-
- Math.max() function is used to return the largest number among two numbers.
- Math.min() function is used to return the smallest number among two numbers.
- Math.floor() function is used to return the lower integer for the argument.
- Math.ceil() is used to return the higher integer for the given argument.
Similar questions