日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java中立方根方法_java基础:4、java中Math类的常用方法?

發布時間:2023/12/4 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java中立方根方法_java基础:4、java中Math类的常用方法? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

4、java中Math類的常用方法?

Java的Math類封裝了很多與數學有關的屬性和方法。如下所示:

System.out.println("計算平方根--Math.sqrt(81)--? "+Math.sqrt(81));//9.0

System.out.println("計算立方根--Math.cbrt(27)--? "+Math.cbrt(27));//3.0

System.out.println("計算x與y平方和的平方根--Math.sqrt(3,4)--? "+Math.hypot(3, 4));//5.0

System.out.println("計算a的b次方--Math.pow(4,2)--"+Math.pow(4,2));//16.0

System.out.println("計算e的x次方--Math.exp(3)--"+Math.exp(3));//20.085536923187668

System.out.println("求最大值--Math.max(81,56)--"+Math.max(81,56));//81

System.out.println("求最小值--Math.min(3.1,6.6)--"+Math.min(3.1,6.6));//3.1

System.out.println("求絕對值--Math.abs(90.4)--"+Math.abs(90.4));//90.4

System.out.println("求絕對值--Math.abs(-81.6)--"+Math.abs(-81.6));//81.6

//天花板

System.out.println("返回比它大的最小整數--Math.ceil(-10.1)--"+Math.ceil(-10.1));//-10.0

System.out.println("返回比它大的最小整數--Math.ceil(10.7)--"+Math.ceil(10.7));//11.0

System.out.println("返回比它大的最小整數--Math.ceil(-0.7)--"+Math.ceil(-0.7));//0.0

System.out.println("返回比它大的最小整數--Math.ceil(0.0)--"+Math.ceil(0.0));//0.0

//地板

System.out.println("返回比它小的最大整數--Math.floor(-10.1)--? "+Math.floor(-10.1));//-11.0

System.out.println("返回比它小的最大整數--Math.floor(10.7)--? "+Math.floor(10.7));//10.0

System.out.println("返回比它小的最大整數--Math.floor(-0.7)--? "+Math.floor(-0.7));//-1.0

System.out.println("返回比它小的最大整數--Math.floor(-0.0)--? "+Math.floor(-0.0));//-0.0

System.out.println("返回比它小的最大整數--Math.floor(-2.5)--? "+Math.floor(-2.5));//-3.0

//隨機數

System.out.println("[0,1)之間的隨機數--? "+Math.random());//0.48482777399357113

System.out.println("[0,100)之間的隨機數--? "+Math.random()*100);//92.73258074803167

//四舍五入,返回double值

System.out.println("返回最接近參數的整數,若兩個數同樣接近,返回偶數那個--Math.rint(-2.5)--? "+Math.rint(-2.5));//-2.0

System.out.println("返回最接近參數的整數,若兩個數同樣接近,返回偶數那個--Math.rint(-1.9)--? "+Math.rint(-1.9));//-2.0

System.out.println("返回最接近參數的整數,若兩個數同樣接近,返回偶數那個--Math.rint(2.5)--? "+Math.rint(2.5));//2.0

System.out.println("返回最接近參數的整數,若兩個數同樣接近,返回偶數那個--Math.rint(10.7)--? "+Math.rint(10.7));//11.0

System.out.println("返回最接近參數的整數,若兩個數同樣接近,返回偶數那個--Math.rint(-1.3)--? "+Math.rint(-1.3));//-1.0

//四舍五入,float返回int類型,double返回long類型

System.out.println("四舍五入--Math.round(-0.7)--? "+Math.round(-0.7));//-1

System.out.println("四舍五入--Math.round(-1.5)--? "+Math.round(-1.5));//-1

System.out.println("四舍五入--Math.round(-10.07)--? "+Math.round(-10.07));//-10

System.out.println("四舍五入--Math.round(-2.5)--? "+Math.round(-2.5));//-2

System.out.println("比a大一點點的浮點數--Math.nextUp(2.5)--? "+Math.nextUp(2.5));//2.5000000000000004

System.out.println("比a小一點點的浮點數--Math.nextDown(2.5)--? "+Math.nextDown(2.5));//2.4999999999999996

System.out.println("比a大或者小一點點的浮點數--Math.nextAfter(1.2,2.5)--? "+Math.nextAfter(1.2,2.5));//1.2000000000000002

System.out.println("比a大或者小一點點的浮點數--Math.nextAfter(1.2,-1)--? "+Math.nextAfter(1.2,-1));//1.1999999999999997

總結

以上是生活随笔為你收集整理的java中立方根方法_java基础:4、java中Math类的常用方法?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。