Give the output of the following program segment: double x = 2.9 , y = 2.5 ;
System.lut.println(Math.min (Math.floor(x),y));
System.out.println(Math.max(Math.ceil(x),y));
Don't spam solve for points
Answers
Corrected question:
Give the 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));
Answer:
==> 2.0
==> 3.0
Explaination:
Here we have been provided with the values of x and y.
Math.floor returns us the largest integer which is less than or equal to that given argument.
==> Math.min (Math.floor (2.9)2.5)
Largest integer would be 2.0
==> Math.min (2.0 , 2.5)
Math.min returns us the smallest of the given two arguments.
As 2.0 is less than 2.5. So, answer would be 2.0
==> 2.0
________________
As we know that Math.ceil returns us the smallest integer which would be greater than or equal to the given argument.
==> Math.max (Math.ceil(2.9) , 2.5)
Smallest integer would be 3.0
As again we know that Math.max returns us the largest integer of the given two arguments.
Largest integer between 2.5 and 3.0 is 3.0
==> 3.0
Return type:
- Math.ceil's return type is double
- Math.max's return type is Same as argument
- Math.min's return type is also same as argument
- Math.floor's return is double.
Additional information:
• Method is a named block of a códe in a class. It is executed within a defined set of instructions.
• Methods and variables of math class are defined as static members.
• Java.lang package contains classes and interfaces which are fundamental to Java programming language.
• The math class of java.lang package contains generic mathematical functions including some geometric and trigonometric function.
Syntax : Math.MethodName(arguments)
• Math.cbrt returns cube root of a double value.
Correct Question
- Give the output of the following program segment: [ICSE 2012]
language