算术计算
• Math.sqrt() : 计算平方根
• Math.cbrt() : 计算立方根
• Math.pow(a, b) : 计算a的b次方
• Math.max( , ) : 计算最大值
• Math.min( , ) : 计算最小值
• Math.abs() : 取绝对值
System.out.println(Math.sqrt(25)); // 5.0
System.out.println(Math.cbrt(27)); // 3.0
System.out.println(Math.pow(4, 2)); // 16.0
System.out.println(Math.max(2, 4));// 4
System.out.println(Math.min(2, 4));// 2
/**
- abs求绝对值
/
System.out.println(Math.abs(-11.4)); // 11.4
System.out.println(Math.abs(11.1)); // 11.1
进位
• Math.ceil(): 天花板的意思,就是逢余进一
• Math.floor() : 地板的意思,就是逢余舍一
• Math.rint(): 四舍五入,返回double值。注意.5的时候会取偶数
• Math.round(): 四舍五入,float时返回int值,double时返回long值
/* - ceil天花板的意思,就是逢余进一
*/
System.out.println(Math.ceil(-10.1)); // -10.0
System.out.println(Math.ceil(10.1)); // 11.0
System.out.println(Math.ceil(-0.5)); // -0.0