Java Math

The Java Math class provides a variety of methods that allow you to perform mathematical operations on numbers.

Tutorials dojo strip



Math.max(x, y)

The Math.max(x, y) method is used to find the highest value between x and y:

JAVA




Math.min(x, y)

The Math.min(x, y) method is used to find the lowest value between x and y:

JAVA




Math.sqrt(x)

The Math.sqrt(x) method returns the square root of x:

JAVA




Math.abs(x)

The Math.abs(x) method returns the absolute (positive) value of x:

JAVA




Random Numbers

The Math.random() method returns a random number between 0.0 (inclusive) and 1.0 (exclusive):

JAVA

To gain more control over the random number, such as generating a number between 0 and 100, you can use the following formula:

JAVA

Tutorials dojo strip