ICSE Class 10 Computer Applications Question 4 of 14

Mathematical Library Methods — Question 4

Back to all questions
4
Question

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()

Returns the square root of its argument as a double value. For example, Math.sqrt(25) will return 5.0.

iii. Math.cbrt()

Returns the cube root of its argument as a double value. For example, Math.cbrt(27) will return 3.0.

iv. Math.random()

Returns a positive double value, greater than or equal to 0.0 and less than 1.0.

v. Math.round()

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()

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.