Math common method in Java

the java.text.SimpleDateFormat Import; 
Import java.util.Date; 

public Test4 class { 

    public static void main (String [] args) { 
        / ** 
         * the Math.sqrt () // calculate the square root 
         * Math.cbrt () // calculating the cubic root 
         * Math.pow (a, b) // calculate a power of b 
         * Math.max (,); // calculate the maximum value 
         * Math.min (,); // calculate the minimum 
         * / 

        the System.out .println (the Math.sqrt (16)); //4.0 
        System.out.println (Math.cbrt (. 8)); //2.0 
        System.out.println (Math.pow (3,2-)); //9.0 
        System.out.println (Math.max (2.3,4.5)); 4.5 of 5 // 
        System.out.println (Math.min (2.3,4.5)); // 2.3 

        / ** 
         * absolute value ABS 
         * /
        System.out.println (the Math.abs (-10.4)); //10.4 
        System.out.println (the Math.abs (10.1)); //10.1 

        / ** 
         * ceil ceiling means, a large value is returned 
         * / 
        System.out.println (Math.ceil (-10.1)); //-10.0 
        System.out.println (Math.ceil (10.7)); //11.0 
        System.out.println (Math.ceil (-0.7) ); //-0.0 
        System.out.println (Math.ceil (0.0)); //0.0 
        System.out.println (Math.ceil (-0.0)); //-0.0 
        System.out.println (the Math. ceil (-1.7)); //-1.0 

        / ** 
         * floor floor mean, is the return of small value 
         * /  
        System.out.println (Math.floor (-10.1)); //-11.0
        System.out.println (Math.floor (10.7)); //10.0
        System.out.println (Math.floor (-0.7)); //-1.0 
        System.out.println (Math.floor (0.0)); //0.0 
        System.out.println (Math.floor (-0.0)) ; //-0.0 

        / ** 
         * random made equal to or greater than 0.0 less than 1.0 is not equal to the random number 
         * / 
        System.out.println (Math.random ()); // number less than 0 is greater than 1 double type of 
        System .out.println (Math.random () * 2) ; // 0 is greater than double the number of types less than 1 
        System.out.println (Math.random () * 2 + 1); // is greater than 2, less than 1 double number type 

        / ** 
         * RINT rounded, double return value 
         * .5 time will note that is even embarrassing = abnormal. = 
         * /  
        System.out.println (Math.rint (10.1)); //10.0
        System.out.println (Math.rint (10.7)); //11.0 
        System.out.println (Math.rint (11.5)); //12.0
        System.out.println(Math.rint(10.5));    //10.0
        System.out.println(Math.rint(10.51));   //11.0
        System.out.println(Math.rint(-10.5));   //-10.0
        System.out.println(Math.rint(-11.5));   //-12.0
        System.out.println(Math.rint(-10.51));  //-11.0
        System.out.println(Math.rint(-10.6));   //-11.0
        System.out.println(Math.rint(-10.2));   //-10.0

        /**
         * round 四舍五入,float时返回int值,double时返回long值
         */
        System.out.println(Math.round(10.1));   //10
        System.out.println(Math.round(10.7));   //11
        System.out.println(Math.round(10.5));   //11
        System.out.println(Math.round(10.51));  //11
        System.out.println(Math.round(-10.5));  //-10
        System.out.println(Math.round(-10.51)); //-11
        System.out.println(Math.round(-10.6));  //-11
        System.out.println(Math.round(-10.2));  //-10

    }
}

  

Guess you like

Origin www.cnblogs.com/smartsmile/p/11617264.html