Math

Java Math class provides utility methods to do basic numeric operations like calculating square roots, exponential and logarithm. The Java Math class is declared as final class and all the utility methods are defined as static methods. In addition to that, the Math class also defines two fields, E and PI.

Below given are some of the methods provided by the Math class which are very useful.
1) The abs method returns absolute value of the specified double, float, long or int value.
2) The ceil method returns the smallest double value that is greater than or equal to the specified double value and is a mathematical integer.
3) The floor method returns the largest double value that is less than or equal to the specified double value and is a mathematical integer.
4) The log method returns the natural logarithm of the specified double value.
5) The max method returns the maximum of two double, float, long or int values.
6) The min method returns the minimum of two double, float, long or int values.
7) The pow method returns the first argument number raised to the power of second argument number.
8) The random method returns a random number between 0.0 (inclusive) and 1.0
9) The round method returns the closest long or int value of the specified double or float value respectively.
10) The sqrt method returns rounded positive square root of the specified double value.

Below given are some of the Java Math examples which shows how to use Math class in Java.

Java Math Examples

Join 1000+ fellow learners! Enter your email address below: