Math类的常用方法和静态导入.


1
package Test; 2 /** 3 * 测试Math的常用方法和静态导入 4 * @author 小王同学 5 * 6 */ 7 import static java.lang.Math.*;//使用静态导入以后可以直接使用Math中的常量,不用再使用Math.常量. 8 public class TestMath { 9 public static void main(String[] args) { 10 //测试Math类的常用方法 11 //取整相关操作 12 System.out.println(Math.ceil(3.2));//向上取整后返回double 13 System.out.println(ceil(3.2));//使用静态导入以后 14 System.out.println(Math.floor(3.2));//向下取整返回double 15 System.out.println(floor(3.2));//向下取整返回double 16 System.out.println(Math.round(3.2));//四舍五入 17 System.out.println(round(3.2));//四舍五入 18 System.out.println(Math.round(3.8));//四舍五入 19 //绝对值、开方、a的b次幂等操作 20 System.out.println(Math.abs(-45));//求绝对值 21 System.out.println(Math.sqrt(64));//64开平方 22 System.out.println(Math.pow(5, 2));//5的平方 23 System.out.println(Math.pow(2, 5));//2的5次方 24 //Math类中常用的常量 25 System.out.println(Math.PI); 26 System.out.println(Math.E); 27 //随机数 28 System.out.println(Math.random());// 得到[0,1)的随机数. 29 } 30 31 }

今天是参加北京尚学堂卓越班的第6天加油!

转载于:https://www.cnblogs.com/xw1024/p/11181899.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值