java知识点 --- java.lang.Math常用方法

1.floor向下取整

       用法:Math.floor(num)

       Math.floor(1.9)//1                      Math.floor(-1.9)//-2

2.round四舍五入

      用法:Math.round(num)实际上是等价于Math.floor(num+0.5)

      Math.round(1.5)//2                     Math.round(1.4)//1

      Math.round(-1.4)//-1                  Math.round(-1.5)//-1               Math.round(-1.6)//-2

3.ceil取不小于num的最小整数

       用法: Math.ceil(num)

       Math.ceil(1.4)//2      Math.ceil(1.5)//2             Math.ceil(1.6)//2

       Math.ceil(-1.4)//-1   Math.ceil(-1.5)//-1           Math.ceil(-1.6)//-1

 4.求绝对值

     Math.abs(num)

     Math.abs(-30.5)//30.5

 5.随机数

     Math.random()随机去0~1的数

     (int)(100*Math.random())这样就可以取0~100随机整数

6.幂函数

     Math.pow(a,b)a的b次方

     Math.pow(x,2)就是平方

     Math.pow(x,3)就是立方

7.开根号

     Math.sqrt(num)num的平方根

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值