- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Mathematical Library Methods
Chapter 7
Mathematical Library Methods
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Assignment Questions and Answers
Question 1
How do user-defined methods differ from library methods?
Answer
A user-defined method is a method defined by the user whereas library methods or built-in methods are the methods created by the developers of Java which are available in the form of packages.
Question 2
Distinguish between Math.ceil() and Math.floor() methods.
Answer
| Math.ceil( ) | Math.floor( ) |
|---|---|
|
Returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer |
Returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. |
|
double a = Math.ceil(65.5); |
double b = Math.floor(65.5); |
Question 3
What is wrong with the following statements? Explain.
i. result = (5/10) * Math.sqrt( a );
Answer
(5/10) will lead to integer division as both numerator and denominator are integers. So result of (5/10) will be 0 instead of 0.5 and the entire expression will always result in 0.
ii. result = math.sqrt(b * b - 4 * a * c) / ( 2 * a );
Answer
math should be written as Math. As Java is case-sensitive so it treats math and Math differently.
Question 4
Explain the following Math functions in Java:
i. Math.abs()
Answer
Returns the absolute value of its argument. Its return type is same as the type of its arguments. For example, Math.abs(-5) will return 5.
ii. Math.sqrt()
Answer
Returns the square root of its argument as a double value. For example, Math.sqrt(25) will return 5.0.
iii. Math.cbrt()
Answer
Returns the cube root of its argument as a double value. For example, Math.cbrt(27) will return 3.0.
iv. Math.random()
Answer
Returns a positive double value, greater than or equal to 0.0 and less than 1.0.
v. Math.round()
Answer
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. For example, Math.round(2.5) will return 3.
vi. Math.ceil()
Answer
Returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer. For example, Math.ceil(65.5) will return 66.0.
Question 5
Write Java expressions for the following:
i. The square root of a + 5b3
Answer
Math.sqrt(a + 5 * Math.pow(b, 3))
ii. The cube root of x3+ y3+ z3
Answer
Math.cbrt(x*x*x + y*y*y + z*z*z);
iii. The square root of b2 + 4ac
Answer
Math.sqrt(b * b + 4 * a * c)
Question 6
Write the following as Java expressions:
i.
Answer
Math.cbrt(x * x + 5 * y * y * y)
ii. ∣x + y∣
Answer
Math.abs(x + y)
iii. ∣x3 + y2 − 2xy∣
Answer
Math.abs(Math.pow(x, 3) + Math.pow(y, 2) - 2*x*y)
iv.
Answer
Math.PI / 6*(Math.pow(z, 4) - 2*Math.PI)
v.
Answer
Math.cbrt(z*z - Math.PI)
vi.
Answer
Math.pow(x*x*x - y*y*y, 1/4)
vii.
Answer
(amount*rate) / (1 - (1 / Math.pow(1+rate, n)))
viii.
Answer
(-b + Math.sqrt(b*b - 4*a*c)) / (2*a)
ix.
Answer
Math.pow((1 / L*C) - ((R*R)/(4*C*C)), 1/4)
Question 7
Write valid statements for the following in Java:
i. Print the rounded off value of 14.49
Answer
System.out.println(Math.round(14.49));
ii. Print the absolute value of -0.09
Answer
System.out.println(Math.abs(-0.09));
iii. Print the largest of -67 and -50
Answer
System.out.println(Math.max(-67, -50));
iv. Print the smallest of -56 and -57.4
Answer
System.out.println(Math.min(-56, -57.4));
v. Print a random integer between 25 and 35
Answer
int range = 35 - 25 + 1;
int num = (int)(range * Math.random() + 25);
System.out.println(num);
vi. Print 47.5 raised to the power 6.3
Answer
System.out.println(Math.pow(47.5, 6.3));
vii. Print minimum of -4, -7
Answer
System.out.println(Math.min(-4, -7));
