2020-08-16 19:58:48 +08:00
|
|
|
package Maths;
|
|
|
|
|
2020-08-23 12:40:30 +08:00
|
|
|
import java.util.Random;
|
|
|
|
|
2020-08-16 19:58:48 +08:00
|
|
|
public class Ceil {
|
2020-10-24 18:23:28 +08:00
|
|
|
public static void main(String[] args) {
|
|
|
|
Random random = new Random();
|
|
|
|
for (int i = 1; i <= 1000; ++i) {
|
|
|
|
double randomNumber = random.nextDouble();
|
|
|
|
assert ceil(randomNumber) == Math.ceil(randomNumber);
|
2020-08-16 19:58:48 +08:00
|
|
|
}
|
2020-10-24 18:23:28 +08:00
|
|
|
}
|
2020-08-16 19:58:48 +08:00
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/**
|
|
|
|
* Returns the smallest (closest to negative infinity)
|
|
|
|
*
|
|
|
|
* @param number the number
|
|
|
|
* @return the smallest (closest to negative infinity) of given {@code number}
|
|
|
|
*/
|
|
|
|
public static double ceil(double number) {
|
|
|
|
if (number - (int) number == 0) {
|
|
|
|
return number;
|
|
|
|
} else if (number - (int) number > 0) {
|
|
|
|
return (int) (number + 1);
|
|
|
|
} else {
|
|
|
|
return (int) number;
|
2020-08-16 19:58:48 +08:00
|
|
|
}
|
2020-10-24 18:23:28 +08:00
|
|
|
}
|
|
|
|
}
|