Math(数学工具类)

Math(数学工具类),构造器私有化,方法设置为静态方法

常用的方法:
在这里插入图片描述

 public static void main(String[] args) {
        //abs(int a),绝对值-10返回10,(负负得正)
        int a =-11;
        System.out.println(Math.abs(a));

        //ceil(double a),返回double值,大于或相等于参数,向上取整数
        double x = 12.8;
        double y = 0.3235;
        System.out.println("Math.ceil(" + x + ")=" + Math.ceil(x));
        System.out.println("Math.ceil(" + y + ")=" + Math.ceil(y));
        System.out.println("Math.ceil(-0.65)=" + Math.ceil(-0.65));

        //floor(double a),返回double值,小于或相等于参数,向下取整数

        System.out.println("Math.floor(" + x + ")=" + Math.floor(x));
        System.out.println("Math.floor(" + y + ")=" + Math.floor(y));
        System.out.println("Math.floor(-0.65)=" + Math.floor(-0.65));

        //round(float a)将数字四舍五入,返回int类型
        System.out.println("Math.round(" + x + ")=" + Math.round(x));
        System.out.println("Math.round(" + y + ")=" + Math.round(y));
        System.out.println("Math.round(-0.65)=" + Math.round(-0.35));

        //pow(double a),返回a的b次幕的值
        System.out.println("Math.pow=" + Math.pow(5,2));

        //random();返回int随机数
        int m = (int) (Math.random()*10);
        System.out.println("Math.random=" + m);

    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值