学习随笔-Math
----【希望可以帮助到大家,如有缺漏或者错误的知识点,欢迎大神们在评论区帮忙补充指正】-----
-> 算数运算:
Math.abs(a):取绝对值
Math.sqrt(a):取平方根
Math.cbrt(a):取立方根
Math.max(a, b):取a和b的最大值
Math.min(a, b):取a和b的最小值
Math.pox(a, b):取a的b方根
-> 算数进位:
Math.ceil(a):取大于等于a的最小整数
Math.floor(a):取小于等于a的最大整数
Math.round():四舍五入,double时返回long值,float时返回int值
Math.rint():四舍五入,返回double值
PS:System.out.println(Math.round(10.5)) // 输出11
System.out.println(Math.rint(10.5)) // 输出10.0
-> 随机数:
Math.random():随机返回一个[0.0, 1.0)的数字