java Math

常用静态方法

1、Math.abs()

作用:计算绝对值

2、Math.ceil()

作用:数学坐标轴向右取整

3、Math.floor()

作用:向下取整

4、Math.round()

作用:四舍五入取整

package cn.wt.day08;

public class Demon11 {
    public static void main(String[] args) {
        // 1. 绝对值
        int abs = Math.abs(-10);
        System.out.println(abs);
        // 2. 向上取整
        double ceil = Math.ceil(-9.1);
        System.out.println(ceil);

        // 3. 向下取整
        double floor = Math.floor(-10.9);
        System.out.println(floor);

        // 4.四舍五入
        long round = Math.round(10.6);
        System.out.println(round);
    }
}

猜你喜欢

转载自www.cnblogs.com/wt7018/p/12207531.html