Lesson 7-Mathematical library methods
Choose the correct answer
Q1)
Which of the following is false to find square of a number?
[Link](a,2)
a*a
[Link](a,2)
All of the above
Q 2)
What type of value is returned by [Link]( )?
int
float
double
All
Question 3
Which of the following syntax is true to find the square root of a number?
sqrt(a)
[Link](a)
Squareroot(a)
None
Question 4
Name the class that is used for different Mathematical functions.
[Link]
[Link]
[Link]
None
Question 5
Give the output of the [Link](x); when x = -9.99
-9.99
9.99
0.99
None
Question 6
Give the output of [Link](x); when x = 9.0
3.0
3.00
all
Predict the output
Question 1
[Link]([Link](10.24));
Output
3.2
Explanation
[Link] method gives the square root of a positive number. Square root of 10.24 is 3.2 so it is the
output.
Question 2
[Link]([Link](-99.4));
Output
-99.0
Explanation
[Link] method rounds off its argument to the nearest mathematical integer and returns its value as a
double type. The nearest integer to -99.4 is -99.0 so that is the output. [Link] method behaves in a
particular way at the mid-point i.e. when the decimal part of the argument is 0.5. In such cases, the
result is the integer value that is even. Let's understand this with an example. [Link](1.5) and
[Link](2.5) will both return 2.0. In the case of 1.5, both 1.0 and 2.0 are equally close to 1.5. [Link]
choses the integer that is even so 2.0 is returned. In the case of 2.5, both 2.0 and 3.0 are equally close to
2.5. [Link] again choses the integer that is even so 2.0 is returned.
Question 3
[Link]([Link](42.875));
Output
3.5
Explanation
[Link] method returns the cube root of its argument as a double value. Cube root of 42.875 is 3.5 so
it is the output.
Question 4
[Link]([Link](-25.5, -12.5));
Output
-25.5
Explanation
[Link] method returns the smaller of its 2 arguments. As -25.5 is smaller than -12.5 so it is the
output.
Question 5
[Link]([Link](-0.95));
Output
-0.0
Explanation
[Link] method returns the smallest double value that is greater than or equal to the argument and is
equal to a mathematical integer. If the argument value is less than zero but greater than -1.0, then the
result is negative zero which is the case in this question.
Question 6
[Link]([Link](-18.51));
Output
-19
Explanation
[Link] method rounds off its argument to the nearest mathematical integer and returns its value
as an int or long type. At the mid-point i.e. when the decimal part of the argument is 0.5, [Link]
method rounds up to the higher integer. In this case, the nearest integer to -18.51 is -19 so it is the
output.
Question 7
[Link]([Link](-77.66, -87.45));
Output
-77.66
Explanation
[Link] method returns the greater of its 2 arguments. As -77.66 is greater than -87.45 so it is the
output.
Question 8
[Link]([Link](-0.88));
Output
-1.0
Explanation
[Link] method returns the largest double value that is less than or equal to the argument and is
equal to a mathematical integer. As -1.0 is the largest mathematical integer less than -0.88 so it is the
output.
Question 9
[Link]([Link](98.5));
Output
98.0
Explanation
[Link] method rounds off its argument to the nearest mathematical integer and returns its value as a
double type. This method behaves in a particular way at the mid-point i.e. when the decimal part of the
argument is 0.5. In such cases, the result is the integer value that is even. Let's understand this with an
example. [Link](97.5) and [Link](98.5) will both return 98.0. In the case of 97.5, both 97.0 and
98.0 are equally close to 97.5. [Link] choses the integer that is even so 98.0 is returned. In the case
of 98.5, both 98.0 and 99.0 are equally close to 98.5. [Link] again choses the integer that is even so
98.0 is returned.
Question 10
[Link]([Link](65.5));
Output
66.0
Explanation
[Link] method returns the smallest double value that is greater than or equal to the argument and is
equal to a mathematical integer. Here 66.0 is the smallest mathematical integer greater than 65.5 so it is
the output.
Write down the syntax for the following functions
Question 1
To find the smaller between two numbers p and q
[Link](p, q)
Question 2
To find the absolute value of a number m
[Link](m)
Question 3
To find the exponent of a number k
[Link](k)
Question 4
To find the square root of a number d
[Link](d)
Question 5
To find the rounded-off of a number b
[Link](b)
Predict the return data type of the following functions
Question 1
[Link]( );
double
Question 2
[Link]( );
double
Question 3
[Link]( );
double
Question 4
[Link]( );
int or long
Question 5
[Link]( );
double
Question 6
[Link]( )
double
Explain the following functions
Question 1
[Link]( )
Returns a positive double value, greater than or equal to 0.0 and less than 1.0.
Question 2
[Link]( )
Returns the greater of its 2 arguments. Its return type is same as the type of its arguments.
Question 3
[Link]( )
Returns the cube root of its argument as a double value.
Question 4
[Link]( )
Returns the absolute value of its argument. Its return type is same as the type of its arguments.
Question 5
[Link]( )
Returns the natural logarithm of its argument. Both return type and argument is of double data type.
Distinguish between them with suitable examples
Question 1
[Link]( ) and [Link]( )
[Link]( )
Returns the smallest double value that is greater than or equal to the argument and is equal to a
mathematical integer
double a = [Link](65.5);
In this example, a will be assigned the value of 66.0 as it is the smallest integer greater than 65.5.
[Link]( )
Returns the largest double value that is less than or equal to the argument and is equal to a
mathematical integer.
double b = [Link](65.5);
In this example, b will be assigned the value of 65.0 as it is the largest integer smaller than 65.5.
Question 2
[Link]( ) and [Link]( )
[Link]( )
Rounds off its argument to the nearest mathematical integer and returns its value as a double type.
At mid-point, it returns the integer that is even
double a = [Link](1.5);
double b =[Link](2.5);
Both, a and b will have a value of 2.0
[Link]( )
Rounds off its argument to the nearest mathematical integer and returns its value as an int or long type.
If argument is float, return type is int, if argument is double, return type is long.
At mid-point, it returns the higher integer.
long a = [Link](1.5);
long b = [Link](2.5);
a will have a value of 2 and b will have a value of 3