Java.Math APIdom
Math.PI 記錄的圓周率
Math.E 記錄e的常量
Math中還有一些相似的常量,都是一些工程數學經常使用量。函數
Math.abs 求絕對值
Math.sin 正弦函數;Math.asin 反正弦函數
Math.cos 餘弦函數;Math.acos 反餘弦函數
Math.tan 正切函數;Math.atan 反正切函數;Math.atan2 商的反正切函數
Math.toDegrees 弧度轉化爲角度;Math.toRadians 角度轉化爲弧度
Math.ceil 獲得不小於某數的最大整數
Math.floor 獲得不大於某數的最大整數
Math.IEEEremainder 求餘
Math.max 求兩數中最大
Math.min 求兩數中最小
Math.sqrt 求開方
Math.pow 求某數的任意次方, 拋出ArithmeticException處理溢出異常
Math.exp 求e的任意次方
Math.log10 以10爲底的對數
Math.log 天然對數
Math.rint 求距離某數最近的整數(可能比某數大,也可能比它小)
Math.round //四捨五入法最接近該參數的int/long值.rem
Math.random 返回0,1之間的一個隨機數數學
public static void main(String args[]) {it
System.out.println("result:"+11+1);
System.out.println("result:"+"12345".valueOf(54321));
double d = -4.4999999;
System.out.println(Math.ceil(d));//不小於參數的最小整數值.
System.out.println(Math.floor(d));//不大於參數的最大整數值.
System.out.println(Math.round(d));//四捨五入法最接近參數的int/long值.
}
輸出爲:io
result:111
result:54321
-4.0
-5.0
-4隨機數