Math Methods

The Java Math class provides several static methods that allows us to work on mathematical calculations with numbers. These methods can be accessed by using the Math class with a given method:

Math.method();

Here are the Math methods in alphabetical order:

Math Methods

.abs()
Returns the absolute value of the argument.
.acos()
Returns the inverse cosine of the argument in radians.
.addExact()
Returns the sum of its arguments.
.asin()
Returns the inverse sine of the argument in radians.
.atan()
Returns the inverse tangent of the argument in radians.
.atan2()
Returns the counterclockwise angle, in radians, between a (x,y) point and the positive x-axis.
.cbrt()
Returns the cube root of a double-type value.
.ceil()
Returns the double value that is a mathematical integer and is greater than or equal to the original value.
.decrementExact()
Returns the argument decremented by one, throwing an exception if the result overflows the datatype.
.floor()
Returns the largest integer value that is less than or equal to the argument. When the provided value is either an integer, zero, not a number, or positive or negative infinity.
.hypot()
Returns the hypotenuse of a right-angled triangle.
.incrementExact()
Returns the argument incremented by one, throwing an exception if the result overflows the datatype.
.log()
Returns the natural logarithm (base e) of a double value as a parameter.
.log10()
Returns the logarithm base 10 of a double value as a parameter.
.log1p()
Returns the natural logarithm (base e) of the sum of a double value as a parameter and 1.
.max()
Returns the maximum value from the given two arguments.
.min()
Returns the minimum value from the given two arguments.
.multiplyExact()
Returns the product of its arguments.
.negateExact()
Returns the negation of the argument and raises an exception if the result overflows.
.nextAfter()
Returns the floating-point number next to the first argument in the direction of the second argument.
.nextDown()
Returns the floating-point value adjacent to the parameter provided in the direction of negative infinity.
.pow()
Returns the first argument raised to the power of the second argument.
.random()
Returns a pseudorandom double that is 0.0 or greater, and less than 1.0.
.rint()
Returns a double that is rounded to the closest whole integer.
.round()
Returns an int or long value that is closest to the number provided.
.scalb()
Returns the first argument multiplied by 2 to the power of the second argument.
.signum()
Used to determine whether a number is positive, negative, zero, or NaN.
.sin()
Returns the trigonometric sine of the specified angle.
.sinh()
Returns the hyperbolic sine of a double-type value.
.sqrt()
Returns the positive, properly rounded square root of a double-type value.
.tan()
Returns the tangent of an angle given in radians.
.tanh()
Returns the hyperbolic sine of a double-type value.
.toDegrees()
Returns an angle measurement converted from radians to degrees.
.toIntExact()
Returns the integer value of a long type argument. An exception is thrown if the value of argument overflows that of an int.
.toRadians()
Converts an angle in degrees to an approximately equivalent angle in radians.
.ulp()
Returns the size of the unit of last precision of a number.

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Java on Codecademy