Java Math Class Methods

The Math class in Java provides a collection of static methods that perform mathematical operations on numbers. These methods are useful for performing tasks like calculating absolute values, trigonometric functions, exponential functions, and more.

This guide covers various methods available in the Math class. Each method is described in simple terms to help beginners understand how to use them. These methods allow you to perform operations such as finding maximum or minimum values, calculating power, and generating random numbers, making it a valuable tool for mathematical computations in Java.

For more detailed information, please refer to the official Java SE Documentation

Java Math Class Methods

The table below contains all the commonly used methods of the Java Math class, each with a link to a detailed explanation, examples, and real-world uses. Click on the method names to learn more about how to use them effectively in your applications.

Method Description
abs() Returns the absolute value of a given number.
absExact() Returns the absolute value of a given exact number.
addExact() Returns the sum of its arguments, throwing an exception if the result overflows an int or long.
asin() Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.
atan() Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.
atan2() Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
cbrt() Returns the cube root of a double value.
ceil() Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
ceilDiv() Returns the division of its arguments, rounded towards positive infinity.
ceilDivExact() Returns the exact division of its arguments, throwing an exception if the result overflows an int or long.
ceilMod() Returns the remainder of division as an integer, rounded towards positive infinity.
clamp() Returns a value constrained to a specified range.
copySign() Returns the first floating-point argument with the sign of the second floating-point argument.
cos() Returns the trigonometric cosine of an angle.
cosh() Returns the hyperbolic cosine of a double value.
floorDiv() Returns the largest (closest to negative infinity) integer value that is less than or equal to the algebraic quotient.
floorMod() Returns the floor modulus of the int or long arguments.
fma() Returns the exact product of the first two arguments summed with the third argument.
log() Returns the natural logarithm (base e) of a double value.
log1p() Returns the natural logarithm of the sum of the argument and 1.
max() Returns the greater of two values.
min() Returns the smaller of two values.
multiplyFull() Returns the full precision product of the arguments.
negateExact() Returns the negation of the argument, throwing an exception if the result overflows.
nextDown() Returns the floating-point value adjacent to the argument in the direction of negative infinity.
pow() Returns the value of the first argument raised to the power of the second argument.
random() Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
round() Returns the closest long or int to the argument.
sin() Returns the trigonometric sine of an angle.
sqrt() Returns the correctly rounded positive square root of a double value.

Comments