JAVA API----Math





public class MathDemo {
    public static void main(String[] args) {

        function_1();
        System.out.println("=============================");
        function_2();
        // exponentiation
        System.out.println("+++++++++++++++");
        function_3();

        //rounding
        System.out.println("****************************");
        function_4();

    }

    /**
     * Returns the absolute value of double
     */
    public static void function_1(){
        double d1=Math.abs(-5);
        System.out.println(d1);

    }

    /**
     * Ceil method, the result is greater than the parameter values ​​of the minimum integer value double
     *
     */
    public static void function_2(){
        double d1=Math.ceil(3.3);
        double d2=Math.ceil(-3.3);
        double d3=Math.ceil(5.1);

        System.out.println(d1);
        System.out.println(d2);
        System.out.println(d3);
    }


    /**
     * Pow method returns the first parameter the second parameter value power
     */

    public static void function_3(){

        double a=Math.pow(2.0,3.0);
        System.out.println("2.0^3.0="+a);
    }

    /**
     * Return the result of rounding
     */

    public static void function_4(){
        double a=Math.round(5.6);

        double b=Math.round(7.3);
        System.out.println("a=5.6");
        System.out.println(a);
        System.out.println("b=7.3");
        System.out.println(b);
    }
}

Guess you like

Origin blog.csdn.net/lieanwan2780/article/details/88564167