Java Math Class Methods

The Math class in Java provides methods for performing basic numeric operations such as elementary exponential, logarithm, square root, and trigonometric functions.

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 enable complex mathematical calculations, making them essential tools in Java programming.

Java Math Methods

The table below contains various 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
absExact() Returns the absolute value of a given number.
acos() Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.
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 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 smallest integer value greater than or equal to the algebraic quotient.
ceilDivExact() Returns the smallest integer value greater than or equal to the algebraic quotient of a division, throwing an exception if the division results in an overflow.
ceilMod() Returns the algebraic quotient, rounded up to the next integer value.
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 value.
floorDiv() Returns the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient.
floorMod() Returns the floor modulus of the int arguments.
fma() Returns the fused multiply-add of the three arguments; that is, (x * y) + z computed with only one rounding error.
log() Returns the natural logarithm (base e) of a 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 product of two int values.
negateExact() Returns the negation of the argument, throwing an exception if the result overflows an int or long.
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 int to the argument, with ties rounding to positive infinity.
round() Returns the closest long to the argument, with ties rounding to positive infinity.
sin() Returns the trigonometric sine of an angle.
sqrt() Returns the correctly rounded positive square root of a value.

The Math class in Java provides a plethora of methods for performing mathematical operations. Understanding and utilizing these methods can significantly enhance your ability to perform complex calculations efficiently.

For more comprehensive details, you can visit the official Java SE documentation.

Leave a Comment

Scroll to Top