通过最近的学习,学到了一些的Math类中的常见方法
package org.stm.demo;

public class Test {

public static void main(String[] args) {

    /**
     * Math.abs(绝对值)
     */
    System.out.println(Math.abs(-11.8));    //11.8
    System.out.println(Math.abs(-0.0));     //0.0
    /**
     * Math.ceil(天花板)
     */
    System.out.println(Math.ceil(-11.8));   //-11.0
    System.out.println(Math.ceil(10.8));    //11.0  
    System.out.println(Math.ceil(-0.6));    //-0.0  
    System.out.println(Math.ceil(0.0));     //0.0  
    System.out.println(Math.ceil(-0.0));    //-0.0  

    /**
     * Math.floor(地板)
     */
    System.out.println(Math.floor(-11.1));  //-12.0  
    System.out.println(Math.floor(11.7));   //11.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 

    /**
     * Math.max(arg0,arg1)
     * Math.min(arg0,arg1)
     */
    System.out.println(Math.max(-11.1, -11));   //-11.0  
    System.out.println(Math.max(11.7, 11));     //11.7  
    System.out.println(Math.max(0.0, -0.0));    //0.0  

    /** 
     * round 四舍五入,float时返回int值,double时返回long值 
     *          Math.round(x) = Math.floor(x+0.5)
     */  
    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  

    /** 
     * rint 四舍五入,返回double值 
     * 注意.5的时候会取偶数 
     */  
    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  
}

}

如果大家有疑问,可评论,也可以到APl中查到相应的用法以及到编辑器里面不妨一试!加油>>>