Math 对象封装了一些数学运算相关的静态属性,和静态方法。
1.静态字段
1.”圆周率Π” 的值
double PI = Math.PI; //3.141592653589793
2.自然对数的底数 e 的值
double E = Math.E; //2.718281828459045
2.静态方法
1.获取绝对值
double abs1 = Math.abs(-5); //5.0
2.取整
double ceil = Math.ceil(5.5); // 向上取整 6.0
double floor = Math.floor(5.5); //向下取整 5.0
3.四舍五入
long r1 = Math.round(3.4); // 3
long r2 = Math.round(3.5); // 4
4.取最值
int max = Math.max(10, 20); //20
5.取随机数
double random = Math.random(); //取值范围 [0,1)