learning java Math类

本文详细介绍了 Java 中 Math 类的各种实用方法,包括取整、四舍五入、求余、幂运算、平方根、立方根等数学操作。通过具体示例展示了 Math.floor、Math.ceil、Math.round、Math.IEEEremainder、Math.pow、Math.sqrt、Math.cbrt 等函数的使用方法。
output:
//取整,返回小于目标数的最大整数
System.out.println(Math.floor(-1.2));
// 取整,返回在于目标数的最大整数
System.out.println(Math.ceil(1.2));
// 四舍五入取整
System.out.println(Math.round(1.6));
System.out.println(Math.round(1.5));
System.out.println(Math.round(1.4));

System.out.println(Math.IEEEremainder(5,3));
System.out.println(Math.IEEEremainder(5,2));

//计算平方
System.out.println(Math.pow(3,4));
//计得平方根
System.out.println(Math.sqrt(4));
// 计算立方根
System.out.println(Math.cbrt(27));

System.out.println(Math.copySign(1.2,-1.0));

System.out.println(Math.nextAfter(1.4,1.0));

System.out.println(Math.nextUp(1.3));
 
-2.0
2.0
2
2
1
-1.0
1.0
81.0
2.0
3.0
-1.2
1.3999999999999997
1.3000000000000003

 

转载于:https://www.cnblogs.com/lianghong881018/p/11245133.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值