0% found this document useful (0 votes)
38 views2 pages

Computer Application IX MathLib

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

Computer Application IX MathLib

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

Mathematical Library Methods

Math class: The Math class of the java.lang package contains many methods that help us
in solving mathematical problems. We can use the methods of Math class using following
syntax-
Math.MethodName (arguments);
There are some important methods of Math class-
 Math.pow(base, exponent) – Returns base raised to exponent. It refers the power to
get base exponent . For example- System.out.println(Math.pow(2, 5)); displays 32.0
(25) , we can also use as- double result = Math.pow(2, 5); to store in variable.
 Math.sqrt(value) – Returns the square root of a given value ( √𝑣𝑎𝑙𝑢𝑒 ). For
example- System.out.println(Math.sqrt(25)); displays 5.0
 Math.cbrt(value) – Returns the cube root of a given value ( √𝑣𝑎𝑙𝑢𝑒 ). For
example- System.out.println(Math.cbrt(125)); displays 5.0
 Math.ceil(value) – It refers ceiling and returns the closest integer that is greater
than or equal to a given value. For example-
System.out.println(Math.ceil(46.6)); displays 47.0
System.out.println(Math.ceil(-46.6)); displays -46.0
 Math.floor(value) – Returns the closest integer that is less than or equal to a given
value. For example- System.out.println(Math.floor(46.6)); displays 46.0
System.out.println(Math.floor(-46.6)); displays -47.0
 Math.round(value) – Returns the closest integer to a given value. For example-
System.out.println(Math.round(46.6)); displays 47
System.out.println(Math.round(-46.6)); displays -47
System.out.println(Math.round(46.5)); displays 47
System.out.println(Math.round(-46.5)); displays -46
Note:- Similar method is Math.rint(value) but it returns in double data type.
 Math.abs(value) – Returns the absolute value (always positive) of a given value.
For example- System.out.println(Math.abs(46.6)); displays 46.6
System.out.println(Math.abs(-46.6)); displays 46.6 ( | -46.6 | )
 Math.max(value1, value2) – Returns the largest of the two given values.
For example- System.out.println(Math.max(46.6, 23.3)); displays 46.6
System.out.println(Math.max(-46, -23)); displays -23
 Math.min(value1, value2) – Returns the smallest of the two given values.
For example- System.out.println(Math.min(46.6, 23.3)); displays 23.3
System.out.println(Math.min(-46, -23)); displays -46
 Math.random() – Returns a random (any value) double value between 0 and 1.
For example- System.out.println(Math.random()); displays any value between
0 and 1each time. But we can change the range using following formula-
int min = 101, max = 200;(To generate random number between 101 to 200)
Computer Applications Notes Volume I (Class IX) for ICSE examinations 2022 by Hem Sir Page 21
int range = max – min +1;
int randomNum = (int) (range * Math.random() + min);

Math.PI - A constant declared in Math class that holds the value of π(3.141592653589793)

There are some examples of mathematical expression with equivalent Java expression-

Computer Applications Notes Volume I (Class IX) for ICSE examinations 2022 by Hem Sir Page 22

You might also like