java.util.math code example

Example 1: math.ceil

Math.ceil(.95);    // 1
Math.ceil(4);      // 4
Math.ceil(7.004);  // 8
Math.ceil(-0.95);  // -0
Math.ceil(-4);     // -4
Math.ceil(-7.004); // -7

Example 2: math class in java

double random = Math.random();
// chooses random number between 0 and 1 ( * 100 to make it in 100)

Example 3: math class in java

double floor = Math.floor(7.343);  // floor = 7.0
//rounds to the value down to the nearest integer value (returned as double)

Example 4: math class in java

int max = Math.max(10, 20);
//returns largest of two value in parameter