| Min and Max | Round | Ceil And Floor |
| Exponents | Random | |
- you can compare all types of numbers, but be aware of autocasting
long a = 5;
int b = 3;
int c = Math.max(a, b);
int c = Math.max(a, b); //OK => 5
int d = (int) Math.max(a, b); //NOK, DOES NOT COMPILE- takes decimal number and returns integral number
- if parameter is float, return type will be int
- if parameter is double, return type will be long
double d = 2.56;
long a = Math.round(d);
// => 3
int b = Math.round(d);//OK
int c = (int) Math.round(d); //NOK, DOES NOT COMPILE
// => 3- take any number and always returns double
double r = Math.ceil(2.45);
// => 3.0
double p = Math.floor(2.45);
// => 2.0
double q = Math.floor(2.99);
// => 2.0- takes any number, returns double
double p = Math.pow(2, 5);
// => 32.0
double q = Math.pow(25, 0.5);
// => 5.0 double ran = Math.random();
// => random number between 0 and 1.0 (not included)private final Random rand = new Random();
public int randomIntNum(){
int min = 50;
int max = 100;
return rand.nextInt(max - min + 1) + min;
}