java中Math类的常用方法

//abs取绝对值:abs(a)

System.out.println("绝对值"+Math.abs(3.2));

//sqrt开平方根:sqrt(a)

System.out.println("开平方根"+Math.sqrt(4));

System.out.println("开平方根"+Math.sqrt(5));

//求幂:pow(double a, double b) a的b次幂

System.out.println("求幂"+Math.pow(3,5));

//向下取整: floor(double a)

System.out.println("向下取整"+Math.floor(3.2));

//向上取整: ceil(double a)

System.out.println("向上取整"+Math.ceil(3.8));

//四舍五入:long round(double a)

System.out.println("四舍五入"+Math.round(5.6));

//随机数:random() 返回0.0到1.0的随机数

System.out.println("随机数"+Math.random());

输出:

绝对值3.2

开平方根2.0

开平方根2.23606797749979

求幂243.0

向下取整3.0

向上取整4.0

四舍五入6

随机数0.06399304352536916

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值