Math Functions

There are many math methods available in Java.

The math methods most likely to be used by students learning Java are explained in more detail here.

Power methods

Math.pow: Raise to power

Math.pow(n,3) returns n to the third, or n*n*n.
Math.pow(2,4) returns 16
Math.pow(81, .5) returns 9 (the square root of 81)

Math.sqrt: square root

Math.sqrt(81) returns 9.
Math.sqrt(0.81) returns 0.9
Trying to find the square root of a negative number returns NaN (value is not defined.)

Math.cbrt: cubic root

Math.cbrt(8) returns 2.

Math.hypot: hypotenuse

Math.hypot(3,4) returns 5

Math.ceil (ceiling) and floor

The ceil method finds the nearest whole number that is >= the argument. You can think of this as moving to the right on a number line.
Math.ceil(5.8) returns 6.
Math.ceil(-5.8) returns -6.

The floor method finds the nearest whole number that is <= the argument. You can think of this as moving to the left on a number line.
Math.floor(5.8) returns 5.
Math.floor(-5.8) returns -6.
ceil-floor

There are also trigonometric methods: cos (cosine), sin (sine), tan (tangent), acos, (arc cosine), asin (arc sine), atan (arc tangent). All of these methods take one argument: the angle expressed in radians. There is also atan2 (arc tangent) which takes 2 parameters: x and y. It returns the arc tangent of y/x, expressed in radians.

There are hyperbolic methods: cosh (hyperbolic cosine), sinh (hyperbolic sine), tanh (hyperbolic tangent), acosh *hyperbolic cosine), asinh (arc hyperbolic sine), and atanh (arc hyperbolic tangent). All of these methods take one argument: the angle expressed in radians.

There are exponential and logarithmic methods and quite a few others.

Please study the material at each of the links below.

  1. Finding the square root
  2. How many busses?
Like us on Facebook:


OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 23 2017 17:41:26.