Math类
Math包含执行基本数字运算的方法
文章目录
abs():返回参数的绝对值
int abs=Math.abs(-10)
结果abs就为10
ceil():向上取整
double ceil=Math.ceil(1.25)
结果ceil就为2
floor():向下取整
double ceil=Math.ceil(1.25)
结果floor就为1
round():四舍五入法
double round=Math.round(1.2);
结果round就为1
double round=Math.round(1.8);
结果round就为2
max():取两个值的较大值
int max=Math.max(1,2)
结果max就为2
min():取两个值的较小值
int min=Math.min(1,2)
结果min就为1
pow(int a,int b):取a的b次幂
double pow=Math.pow(2,3)
结果pow就为8
random():取0到1之间的随机小数
double random=Math.random();
结果为:0.106823445124214;