You are on page 1of 2

Lesson 8

Mathematical Library Functions in Java

Mathematical library functions in java are present inside the Math class of
java.lang package. So to use them we must import java.lang package in our
program.

Following are some of the functions:

Function Syntax Description

Name
pow Math.pow(a,b) Returns the value of the first
argument to the power of the second
argument.

The return type and the arguments


are double.
sqrt Math.sqrt(a) Returns the square root of the given
argument.

The return type and the argument


are double.
cbrt Math.cbrt(a) Returns the cube root of the given
argument.

The return type and the argument


are double.
abs Math.abs(a) Returns the absolute value of the
given argument.

The return type and the arguments


can be double/float/int/long and
data types of the arguments and
return type are same.
ceil Math.ceil(a) Returns a double value which is
either equal or greater than the given
value.

The return type and the arguments


are double.
floor Math.floor(a) Returns a double value which is
either equal or lesser than the given
value.

The return type and the arguments


are double.
round Math.round(a) Returns an integer rounded to the
nearest whole number of the given
value.

The return type and the arguments


are either double or float.

If argument is double then return


type is long and if the argument is
float then return type is integer.
max Math.max(a) Returns the maximum value of the
given two arguments.

The return type and the arguments


can be double/float/int/long and
data types of the arguments and
return type are same.
min Math.min(a) Returns the minimum value of the
given two arguments.

The return type and the arguments


can be double/float/int/long and
data types of the arguments and
return type are same.
Math.random( ) Returns a random double value
which is greater than or equal to 0.0
and less than 1.0
(int)(Math.random( )*n) + 1 Returns a random integer value
random which is greater than or equal to 1
and less than or equal to n.
(int)(Math.random( )*(U-L)) + Returns a random integer value
L which is greater than or equal to L
and less than U.

You might also like