Math Class Methods in Java with Examples

Java Math Class provides several methods to perform mathematical calculations such as avg(),  round(), floor(), max(), tan(), abs(), and so on.

Java Math methods

The java.lang.Math method contains several methods that are used to perform basic numeric operations such as square root, cube root, logarithm, exponential, and trigonometric operations. The various Java methods are described below:

Basic Math methods

  • abs()

This method returns the absolute value of any type of argument passed.

  • max()

This method returns the greater value out of the two arguments passed values.

  • min()

This method returns the smallest value out of the two arguments passed values.

  • round()

This method rounds off the passed argument up to closest decimal places.

  • sqrt()

This method returns the square root value of the argument passed.

  • cbrt()

This method returns the cube root value of the argument passed.

  • pow()

This method returns the value as base raised to the power of the exponent.

  • signum()

This method returns the signum value of the passed argument.

  • ceil()

This method is used to find the smallest possible value which is either greater or equal to the argument passed.

  • copySign()

This method returns the second argument with the sign of the first floating-point argument.

  • nextAfter()

This method returns the floating-point number adjacent to the first argument toward the second argument direction.

  • nextUp()

This method returns the floating-point value adjacent to d in the positive infinity direction.

  • nextDown()

This method returns the floating-point value adjacent to d in the negative infinity direction.

  • floor()

This method returns the closest possible value that is either less than or equal to the passed argument.

  • floorDiv()

This method returns the largest integer value that is less than or equal to the algebraic quotient.

  • random()

This method returns the double value with a positive sign that is greater than or equal to 0.0 and less than 1.0.

  • rint()

This method returns the double value that is closest to the argument passed and similar to the mathematical integer.

  • hypot()

This method returns the hypotenuse of the right-angled triangle without intermediate overflow or underflow.

  • ulp()

This method returns the least distance between two floating point numbers.

  • getExponent()

This method returns the unbiased exponent used in the representation of a value.

  • IEEEremainder()

This method returns the remainder when a dividend is divided by a divisor.

  • subtractExact()

This method returns the difference of the arguments passed.

  • multiplyExact()

This method returns the product of the arguments passed.

  • incrementExact()

This method returns the incremented value of the argument.

  • decrementExact()

This method returns the argument decremented by one.

  • toIntExact()

This method returns the value of the long argument.

Logarithmic Math Methods

  • log()

This method returns the logarithm value of the passed argument.

  • log10()

This method returns the base 10 logarithm value of the argument passed.

  • log1p()

This method returns the natural logarithm of the sum of the argument and 1.

  • exp()

This method returns the Euler’s number rose to the power of the passed argument.

  • expm1()

Trigonometric Math Methods

  • sin()

This method returns the trigonometric sine value of the passed argument.

  • cos()

This argument returns the trigonometric cosine value of the argument passed.

  • tan()

This method returns the trigonometric tangent value of the argument passed.

  • asin()

This method returns the arc sine value of the argument passed.

  • acos()

This method returns the arc cosine value of the argument passed.

  • atan()

This method returns the arctangent value of the passed argument.

Hyperbolic Math Methods

  • sinh()

This method returns the hyperbolic sine of the argument arg.

  • cosh()

This method returns the hyperbolic cosine of the argument arg.

  • tanh()

This method returns the hyperbolic tangent of the argument arg.

Angular Math Methods

  • toDegree

This method converts the specified radians angle to equivalent angle measured in degree.

  • toRadians

This method returns the radians equivalent of the degree-argument passed.

Leave a Reply

Your email address will not be published. Required fields are marked *