Math类小结

JAVA学习网 2017-10-10 07:46:02
package com.swift;

public class MathDemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //数学类的小总结 Math
        System.out.println(Math.pow(4, 3));//幂运算 64
        System.out.println(Math.pow(4, 0.5));//4的开方
        System.out.println(Math.pow(2, -2));//0.25 2的2次幂分之1
        System.out.println(Math.sqrt(16));//0.25 2的2次幂分之1  square root sqrt
        System.out.println(Math.sqrt(25));//0.25 2的2次幂分之1
        System.out.println(Math.abs(-3));//0.25 2的2次幂分之1 absolute
        System.out.println(Math.ceil(2.6));//0.25 2的2次幂分之1 absolute
        System.out.println(Math.ceil(2.1));//0.25 2的2次幂分之1 absolute
        System.out.println(Math.floor(2.1));//0.25 2的2次幂分之1 absolute
        System.out.println(Math.rint(2.1));//0.25 2的2次幂分之1 absolute 返回偶数
        System.out.println(Math.round(2.1));//正数四舍五入,负数五舍六入
    }

}

 

阅读(734) 评论(0)