Give output of the following program segment:
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));
Single Choice
Views 96
Answer:
-
Math.min(Math.floor(x), y)Math.floor(x): This function returns the largest integer less than or equal tox. Forx = 2.9,Math.floor(2.9)returns2.0.Math.min(Math.floor(x), y): This function returns the smaller of the two values:Math.floor(x)andy. Therefore,Math.min(2.0, 2.5)returns2.0.
So,
System.out.println(Math.min(Math.floor(x), y));will print2.0. -
Math.max(Math.ceil(x), y)Math.ceil(x): This function returns the smallest integer greater than or equal tox. Forx = 2.9,Math.ceil(2.9)returns3.0.Math.max(Math.ceil(x), y): This function returns the larger of the two values:Math.ceil(x)andy. Therefore,Math.max(3.0, 2.5)returns3.0.
So,
System.out.println(Math.max(Math.ceil(x), y));will print3.0.
Summary of Output:
2.0 3.0
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.