Java Tutorials
Java Methods
Java Classes
Java File Handling
The Java Math section has many options that allow you to do math tasks on numbers.
The Math.max(x, y)
method can be used to find the highest values of x and y:
Math.max(5, 10);
The Math.min(x, y)
method can be used to find the low value of x and y:
Math.min(5, 10);
The Math.sqrt(x)
method returns the square root x:
Math.sqrt(64);
The Math.abs(x)
method returns the total (positive) value of x:
Math.abs(-4.7);
Math.random()
returns a random number between 0.0 (combined), and 1.0 (special):
Math.random();
For more control over a random number, e.g. you only want a random number between 0 and 100, you can use the following formula:
int randomNum = (int)(Math.random() * 101); // 0 to 100