Java.lang.Math类详解

用于执行基本数学运算的方法!

Math类的所有执行方法都是静态方法,可以直接使用类名.方法名调用

public static void main(String[] args) {
    long round = Math.round(1.6);
    System.out.println("Math.round(1.6) === "+round);
    double rint = Math.rint(2.3);
    System.out.println("Math.rint(2.3) === "+rint);
    double rint1 = Math.rint(2.6);
    System.out.println("Math.rint(2.6) === "+rint1);
    int max = Math.max(1, 2);
    System.out.println("Math.max(1, 2) === "+max);
    double max1 = Math.max(1.25, 1.26);
    System.out.println("Math.max(1.25, 1.26) === "+max1);
}
Math.round(1.6) === 2
Math.rint(2.3) === 2.0
Math.rint(2.6) === 3.0
Math.max(1, 2) === 2
Math.max(1.25, 1.26) === 1.26
 常用的方法:
Math.round()    返回最接近参数的 int,它表示"四舍五入"
Math.rint()         返回最接近参数并等于某一整数的 double 值,如果有2个数同样接近,则返回偶数的那个
Math.floor()       返回最大的(最接近正无穷大)double 值,该值小于等于参数,并等于某个整数
Math.ceil()         返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数
Math.cbrt()        返回 double 值的立方根
Math.sqrt()        返回正确舍入的 double 值的正平方根
Math.pow()       返回第一个参数的第二个参数次幂的值
Math.max()       返回两个 double 值中较大的一个
Math.min()        返回两个 double 值中较小的一个

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值