Previous

Java Math Methods

Method Description Example
abs() Returns the absolute value of a number. Math.abs(-4.7) returns 4.7
acos() Returns the arccosine of a value. Math.acos(0.5) returns approximately 1.047
asin() Returns the arcsine of a value. Math.asin(0.5) returns approximately 0.524
atan() Returns the arctangent of a value. Math.atan(0.5) returns approximately 0.464
cbrt() Returns the cube root of a value. Math.cbrt(27) returns 3
ceil() Returns the smallest integer greater than or equal to a value. Math.ceil(4.2) returns 5
cos() Returns the cosine of an angle. Math.cos(Math.PI) returns -1
cosh() Returns the hyperbolic cosine of a value. Math.cosh(0) returns 1
exp() Returns the base of the natural logarithm (e) raised to a power. Math.exp(1) returns approximately 2.718
floor() Returns the largest integer less than or equal to a value. Math.floor(4.7) returns 4
log() Returns the natural logarithm (base e) of a value. Math.log(Math.E) returns 1
log10() Returns the base 10 logarithm of a value. Math.log10(100) returns 2
max() Returns the largest of two values. Math.max(5, 10) returns 10
min() Returns the smallest of two values. Math.min(5, 10) returns 5
pow() Returns the value of a base raised to the power of an exponent. Math.pow(2, 3) returns 8
random() Returns a random number between 0 (inclusive) and 1 (exclusive). Math.random() returns a random number
rint() Returns the closest integer to a value. Math.rint(2.4) returns 2
round() Returns the value of a number rounded to the nearest integer. Math.round(4.7) returns 5
signum() Returns the signum function of a value. Math.signum(-5) returns -1
sin() Returns the sine of an angle. Math.sin(Math.PI/2) returns 1
sinh() Returns the hyperbolic sine of a value. Math.sinh(0) returns 0
sqrt() Returns the square root of a value. Math.sqrt(16) returns 4
tan() Returns the tangent of an angle. Math.tan(0) returns 0
tanh() Returns the hyperbolic tangent of a value. Math.tanh(0) returns 0
toDegrees() Converts an angle measured in radians to an approximately equivalent angle measured in degrees. Math.toDegrees(Math.PI) returns approximately 180
toRadians() Converts an angle measured in degrees to an approximately equivalent angle measured in radians. Math.toRadians(180) returns Math.PI
Previous