In this example you will learn about Math class.
Java - Math class in Java
In this example you will learn about Math class. This example explains how you can use functions provided by the Math class like E, PI, round, abs, ceil, exp, floor, IEEEremainder, max, min, pow, random, rint, sqrt etc. to manipulate the mathematical operation in your program. The Math class is used to operate the calculations. There is not necessary to import any package for the Math class because this is already in java.lang package.
Any expressions can be operated through certain method calls. There are some functions have been used in the given example. All the functions have been explained below with example :
E
This is E field of the Math class which returns you a default exponent value that is closer than any other to e, the base of the natural logarithms.
PI
This is also a field of the Method class which returns you a default pi value, the ratio of the circumference of a circle to its diameter.
abs()
This is the abs() function which returns you the absolute number.
ceil()
This is the ceil() function which returns you the smallest value but greater than the argument.
exp()
This is the exp() function which returns you the exponential value raised to the power of a double value.
floor()
This is the floor() function which returns you the largest value but less than the argument.
IEEEremainder()
This is the IEEEremainder() which returns you the remainder for the given dividend and divisor.
max()
This is the max() function which distinguishes the maximum value from the two given value.
min()
This is the min() function which distinguishes the minimum value from the two given value.
pow()
This is the pow() function which returns you the number raised to the power of a first given value by the another one.
random()
This is the random() function which returns you the random number. It is absolutely system generated.
rint()
This is the rint() function which returns you a value closest to the given value.
round()
This is the round() function which returns you a value that is in the rounded form.
sqrt() 0
This is the sqrt() function which returns you the square root of the specified value.
Code for the program :
|