0% found this document useful (0 votes)
8 views

Java Mathematical Functions (1)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java Mathematical Functions (1)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mathematical Library Functions

• Java has many built-in packages like java.lang, java.util, java.io etc.
• The java.lang package is imported by default by the java compiler. This
package contains many classes that are required for designing a program.
• The Math class of the java.lang package contains functions / methods for
performing mathematical and trigonometrical functions.
Note : you can invoke the methods of Math class with the class name
directly without creating an object for the class.

SNO FUNCTION SYNTAX WITH DESCRIPTION


( EXAMPLE )
1. Math.sqrt(); Syntax: Returns the square root of
Math.sqrt(n); the given number.
Eg:- It returns a double datatype
Math.sqrt(4); value.
2.0

2. Math.cbrt(); Syntax: Returns cube root of the


Math.cbrt(n); number.
Eg:- It returns a double datatype
Math.cbrt(125); value.
5.0

3. Math.pow(); Syntax: Returns the value of the first


Math.pow(a,b); number raised to the power
Eg:- of the second number.
Math.pow(10,2); (first number is base and
100.0 second number is exponent)
It returns a double datatype
value.

4. Math.max(); Syntax: Returns the largest of the


Math.max(a,b); two given numbers.
Eg:- The return type depends
Math.max(106,104); upon the datatype of given
106 numbers.
Math.max(-10, -7);
-7
5. Math.min(); Syntax: Returns the smallest of the
Math.min(a,b); two given numbers.
Eg:- The return type depends
Math.min(- 7.5,-10.6); upon the datatype of the
- 10.6 given numbers.

6. Math.abs(); Syntax: Returns the absolute value


Math.abs(n); (ignoring the sign) of the
Eg:- given number.
Math.abs(-10.6); The return type depends
10.6 upon the datatype of the
value given.

7. Math.ceil(); Syntax: Return the closest higher


Math.ceil(a); integer value( >=).
Eg:- It returns a double type
Math.ceil (10.6); value.
11.0
Math.ceil(- 14.56)
-14.0
( - 14.56 is between
- 14 and - 15
- 14 is the closest
higher integer value)

8. Math.floor(); Syntax: Return the closest lower


Math.floor(a); integer value(<=).
Eg:- It returns a double datatype
Math.floor (10.6); value.
10.0
Math.floor(-14.56);
-15.0

9. Math.round(); Syntax: Returns the rounded value


Math.round(a); of the given number.
Eg:- It returns an integer
Math.round(10.6); datatype value.
11

x------------------------------------------------------x

You might also like