Computer Science, asked by yeshukiraah, 1 month ago

1) What do the following functions return:
double x=13.89, y=37.123;
System.out.println(Math.floor(x)+Math.ceil(y));

i. 42.0
ii. 52.0
iii. 51.0
iv. 50.0​

Answers

Answered by Anonymous
4

Given :

double x=13.89, y=37.123;

To Find :

Output of Math.floor(x) + Math.ceil(y).

Solution :

  • x = 13.89
  • y = 37.123

System.out.println(Math.floor(x)+Math.ceil(y));

→ Math.floor(x)

= Math.floor(13.87)

= 13.0

→ Math.ceil(y)

= Math.ceil(37.123)

= 38.0

Math.floor(x)+Math.ceil(y)

= 13.0 + 38.0

= 51.0

System.out.println(Math.floor(x)+Math.ceil(y));

51.0

Your answer is option (iii).

The answer is 51.0.

Explanation :

  • Math.floor returns the value down to the nearest integer whose return type is double. So, we get Math.floor as 13.0.
  • Math.ceil returns the next higher integer of the number whose return type is double. So, we get Math.ceil as 38.0.
  • Now adding 13.0 and 38.0 we get 51.0

Explore More :

  • The library methods are in built methods designed by the developers.
  • The library classes as follows: Math.min(), Math.max(), Math.pow(), Math.sqrt(), Math.cbrt(), Math.log(), Math.abs(), Math. round(), Math.rint(), Math.ceil(), Math.floor(), and Math.exp().
  • All the function has e return type of double except min(), max() and abs().
Similar questions