public class MathDemo {
public static void main(String args[]){
/**
* abs求絕對值
*/
System.out.println(Math.abs(-10.4)); //10.4
System.out.println(Math.abs(10.1)); //10.1
/**
* ceil天花板的意思,就是返回大的值,注意一些特殊值
*/
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
/**
* floor地板的意思,就是返回小的值
*/
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
/**
* max 兩個中返回大的值,min和它相反,就不舉例了
*/
System.out.println(Math.max(-10.1, -10)); //-10.0
System.out.println(Math.max(10.7, 10)); //10.7
System.out.println(Math.max(0.0, -0.0)); //0.0
/**
* random 取得一個大於或者等於0.0小於不等於1.0的隨機數
*/
System.out.println(Math.random()); //0.08417657924317234
System.out.println(Math.random()); //0.43527904004403717
/**
* 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
/**
* 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
}
}
轉自:http://blog.csdn.net/lixiang0522/article/details/7557851
Math.PI 記錄的圓周率,其值爲:3.14159265358979323846
Math.E記錄e的常量,其值爲:2.7182818284590452354
8)Math.sqrt(25);//返回指定數字的平方根(取到的數字的值,這個函數用來給參數開方)返回5
Math.cos() 餘弦函數 Math.acos() 反餘弦函數
Math.tan() 正切函數 Math.atan() 反正切函數 (Math.tan() 返回正切值爲指定數字的角度)
Math.atan2() 商的反正切函數
Math.toDegrees() 弧度轉化爲角度 Math.toRadians() 角度轉化爲弧度