java.lang.Math


*******************************************************

1. The round method

long result = Math.round(1.667);    // result is 2
int result  = Math.round(1.49F);    // result is 1


*******************************************************


2. The pow method

double result = Math.pow(2, 2);   // result is 4.0 (2.2)
double result = Math.pow(2, 3);   // result is 8.0 (2 * 2 * 2)
double result = Math.pow(5, 2);   // result is 25.0 (5 squared)
int result = (int) Math.pow(5, 2); //result is 25 (5 squared)


*******************************************************


3. The sqrt method

double result = Math.sqrt(20.25);   // result is 4.5


*******************************************************


4. The max and min methods

int x = 67;
int y = 23;
int max = Math.max(x, y);    // max is 67
int min = Math.min(x, y);    // min is 23



*******************************************************


5. The random method


double x = Math.random() * 100;  // result is a value >= 0.0 and  < 100.0
long result = (long) x;          // converts the result from double to long 


 
*******************************************************






Site hosted by Angelfire.com: Build your free website today!