Java Math
The Java Math class is built into Java and provides a range of methods that make it easy to work with constants and will execute common mathematical calculations like rounding up or down numbers, or finding the largest or smallest in a range numbers. The list is pretty extensive and in this lesson you will learn how to use the most common and useful Math methods.The following table contains some for the most common Math methods:
Method | Purpose | Returns |
---|---|---|
max() | Greater of two numbers, 2 arguments required | int, double, float or long |
min() | Smaller of two numbers, 2 arguments required | int, double, float or long |
round() | Rounds up or down to closest integer | int |
floor() | Rounds down to closest integer below a give number | double |
ceil() | Rounds up to closest integer above a given number | double |
pow() | First argument to power of second | double |
random() | Random positive value between 0.0 and 1.0 | double |
sqrt() | Square root of a number | double |
What you will learn
In this lesson you will learn about common Java Math constants and methods, and how to use them.