When we write a program, we may need to calculate the square root of a number, or the absolute value, or obtain a random number, etc.
The Math class in the java.lang package contains many class methods used for scientific calculations. These methods can be called directly through the class name.
In addition, the Math class also has two static constants E and PI , whose values are 2.7182828284590452354 and 3.14159265358979323846 respectively.
Common class methods of the Math class are as follows:
Returns the absolute value of a.
Returns the maximum value of a and b.
Return the minimum value of a and b.
Generate a random number between 0 and 1 (excluding 0 and 1).
Returns a raised to the b power.
Returns the square root of a.
Returns the logarithm of a.
Returns the sine of a.
Returns the arcsine of a.