0% found this document useful (0 votes)
1K views9 pages

Chapter 7 Mathematical Library Methods. EMCQs

java

Uploaded by

Aditya Laha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views9 pages

Chapter 7 Mathematical Library Methods. EMCQs

java

Uploaded by

Aditya Laha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Tick () the correct option.

1. Which among the following package is imported by default:


a. [Link]
b. [Link]
c. Both a and b
d. None of these
Ans. a. [Link]

2. Which among the following class do not belong to the [Link] package?
a. System
b. String
c. Math
d. Scanner
Ans. d. Scanner

3. Which among the following function returns the absolute value of a number?
a. [Link]( ) // Does not exist but it is abbreviated form of abs function
b. [Link]( )
c. [Link]( )
d. [Link]( )
Ans. c. [Link]( ) (Returns absolute number (eg. -1 to 1) only removes -ve sign.)

4. Which among the following will yield -1 for negative number and 1 for positive number
for a
number stored in a variable a?
a. [Link](a)*a
b. [Link](a) / a
c. [Link](a) / [Link](a)
d. None of these
Ans. b. [Link](a) / a

5. Which among the following gives the next mathematical integer?


a. [Link]( )
b. [Link]( ) // Rounds off a decimal or float value.
c. [Link]( ) // Find number from a limited range. By default, it is (1). The range must
be multiplied
d. All of these
Ans. b. [Link]( ) // Gives output as a round number. If it is a decimal, it returns only a
whole number.***********************

6. What is the return type of [Link](1,2.0f)?


a. float
b. double
c. int
d. long
Ans. a. float
7. Which among the following expression will return a random integer between 5 and 10
both
inclusive?
a. 5+(int)([Link]()*6) // This random function walks from 0 Thus on adding 5 and
then multiplying with 6 It results in 10 (0-5 & 5-10).
b. 5+(int)([Link]()*10)
c. 5+[Link]()*6
d. 5+[Link]()*10
Ans. a. 5+(int)([Link]()*6)

8. Which among the following function is equivalent to [Link](a)?


a. [Link](a); // To find cube root What is mac dot
b. [Link](a,1/2)
c. [Link](a,1/2.0);
d. Math.
Ans. c. [Link](a,1/2.0); //// Power functions always works in Double

9. What value will [Link](-9) return?


a. -3.0
b. 3.0
c. NaN
d. None of these
Ans. c. NaN // Square root does not work for negative numbers.

10. What value will [Link]([Link](8.1)) return?


a. 9.0
b. 9
c. 3.0
d. 4.0
Ans. c. 3.0 // [Link] Function If there is 8.1 though there is 1 after decimal, it will take 9.

SECTION A
A. Answer the following questions.
1. Name the class that is used for different mathematical functions. Give an example of a
mathematical function.
Ans. class: Math
Functions: [Link](), [Link](), [Link](), etc. // [Link]() function rounds a
decimal number as well as remove the decimal number to (.0) e.g- 49.51 to 50.0
In Java, the [Link]() and [Link]() functions are essential tools for rounding floating-point
numbers to the nearest integer, each with its unique behavior:
1. 1. [Link]():

o The ceil function stands for “ceiling.”


o It returns an integer that is just greater than or equal to a given rational value.
o For example, the ceil value of 3.138 is 4 (not the round-off value, which would be
3).
o It is represented as ceil(x).
2. [Link]():
o The floor function stands for “floor.”
o It returns an integer that is just lesser than or equal to a given rational value.
o For example, the floor value of 3.883 is 3 (not the round-off value, which would be
4).
o It is represented as floor(x)

2. Give the output of the following expressions.


i. If x = -9.99, calculate [Link](x);
ii. If x = 9.0, calculate [Link](x);
Ans. i. 9.99
ii. 3.0

B. Give the output of the following functions:


1. [Link](-126.349) // Gives output as a round number irrespective of sign.
Ans. -127.0

2. [Link](45.6,17.3) // Gives the maximum number as output


Ans. 45.6

3. [Link](-0.0,0.0)
Ans. -0.0

4. [Link](4,3)
Ans. 64.0

5. [Link](625) // Returns value as a double


Ans. 25.0

6. [Link](125) // Returns value as double


Ans. 5.0

7. [Link](11,11)
Ans. 11

8. [Link](-12.56)
Ans. -12.0

9. [Link](15.36) *******************************
Ans. 15.0

10. [Link](146.5) // Rounds off a decimel place


Ans. 147.0

C. Write equivalent Java expressions for the following:


i.√ a+b
Ans. [Link](a+b)

1 3 1 3
ii. a+ b
3 4
Ans. 1/3.0*[Link](a,3)+1/4.0*[Link](b,3)

1 2
iii. s=ut+ a t
2
Ans. s=u*t+1/2.0*a*[Link](t,2);

iv. d = √ l 2+ b2
Ans. d=[Link](l*l+b*b);

v.
Ans. (-b+[Link](b*b-4*a))/(2*a)

vi.
Ans. ([Link](a,3)+[Link](b,3))/([Link](a,3)-[Link](b,3))

vii. // For absolute function in Java, this mathematical sign is used.


Ans. [Link]((a-b)/(a+b))

viii.
Ans. [Link]((a+b)/(a*b))

ix.
Ans. [Link](5*x*x+y)/[Link](x+11*y*y*y, 1/4.0) // This format is used for any kind
of root after cube.

x.
Ans. (x+y)/[Link]([Link](x-y))

All mathematical functions are included in a class called


Math (Correct)
System
Scanner

Math class is a part of Java.________ package


io
util
lang (Correct)

what will be the output of [Link](-4.0)


2
-2
NaN (Correct)

What will be the return value of [Link](2.0,3.0)


8.0 (Correct)
8
NaN

In the function [Link](a,b), b ( the index)can take a negative value


True (Correct)
False
NA

The return value of [Link](-15.625) is


2.5
-2.5 (Correct)
NaN

The return data type for the [Link]() is________


float
integer (Correct) // Or float also
double

[Link]() will always return _____ data type


integer
float
double (correct)

The output of the function [Link](-31.987)


-31 (Correct) vvi *** For negative number this function always rounds
near zero. Thus it will always remain the same number, though there is a
greater number in the decimal
-32
-30

The output of the function [Link](-9.0)


-9 (Correct)
-8
-10

The output of the function [Link](-0.9)


1
0
-1 (Correct)

This functions returns a random number between 0 and 1


[Link]()
[Link]() (Correct)
[Link]()

The methods which are created by system developers are called ________
library method
built-in method
both (Correct)

[Link]()*n+1 generates number between


1 and 0
1 and n (Correct)
0 and n

[Link]()*(n-m) +m generates a number between


m and n (Correct)
n and m
1 and m

[Link]() returns a double value r such that

1. 0.0 <= r < 1.0 ✓


2. 0.0 <= r <= 1.0
3. 0.0 < r <= 1.0
4. 0.0 < r < 1.0

Give the output of [Link](46.6)?********************

1. 46.5
2. 47.0
3. -46.0
4. 46.0 ✓

What is [Link] The [Link]() method in Java is used to round the argument to the nearest
mathematical integer. Here’s the syntax:

5. Which of these method is a rounding function of Math class?


a) max()
b) min()
c) abs()
d) all of the mentioned (Correct)

6. Which of these class contains only floating point functions?


a) Math (Correct)
b) Process
c) System
d) Object

7. double d = [Link] ( 2.5 + [Link]() );

a) 2
b) 3 (Correct)
c) 4
d) 2.5

[Link] type of value is returned by [Link] ( )?

a) int b) float

c) double (correct) d) All

4. Name the class that is used for different Mathematical functions


a) [Link] (correct) b) [Link]

c) [Link] d) None

5. Give the output of the [Link](x) ; when x = – 9.99

a) -9.99 b) 9.99 (correct)

c) 0.99 d) None

2. [Link]([Link](-99.4)); Ans. – 99.0

IV. Predict the return data type of the following functions: *********

1. [Link]( ); Ans. double

2. [Link]( ); Ans. double

[Link](); Ans: double

4. [Link]( ); Ans. integer

5. [Link]( ); Ans. double

6. [Link]( ); Ans. double

6. Which of these class encapsulate the runtime state of an object or an interface?


a) Class (correct)
b) Object
c) Runtime
d) System

You might also like