The Java Math class offers a variety of methods enabling you to execute mathematical operations and calculations with numbers.
You can utilize the Math.max(x, y) method to determine the greater value between x and y.
|
The Math.min(x, y) method facilitates identifying the smaller value between x and y:
Math.min(5, 10); |
The Math.sqrt(x) method provides the square root value of x.
Math.sqrt(64); |
The Math.abs(x) method yields the absolute, or positive, value of x.
Math.abs(-4.7); |
Math.random() generates a random number within the range of 0.0 (inclusive) to 1.0 (exclusive).
|
For finer control over random number generation, such as limiting it to a range like 0 to 100, you can employ the following formula:
|