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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

【蓝桥杯Java_C组·从零开始卷】第六节(一)、Java常用数学函数

發(fā)布時間:2024/8/26 java 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【蓝桥杯Java_C组·从零开始卷】第六节(一)、Java常用数学函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

1.Math.sqrt() : 計算平方根

2.Math.cbrt() : 計算立方根

3.Math.pow(a, b) : 計算a的b次方

4.Math.max( , ) :計算最大值

5.Math.min( , ) : 計算最小值

6.Math.abs() : 取絕對值

7.Math.ceil(): 向上取整

8.Math.floor() : 向下取整

9.Math.rint(): 四舍五入,返回double值。注意.5的時候會取偶數(shù)

10.Math.round(): 四舍五入,float時返回int值,double時返回long值

11.Math.random(): 取得一個[0, 1)范圍內(nèi)的隨機數(shù)

12.π


1.Math.sqrt() : 計算平方根

System.out.println(Math.sqrt(25)); // 5.0

2.Math.cbrt() : 計算立方根

System.out.println(Math.cbrt(27)); // 3.0?

3.Math.pow(a, b) : 計算a的b次方

System.out.println(Math.pow(3, 2)); // 9.0

4.Math.max( , ) :計算最大值

System.out.println(Math.max(2.3, 4.5));// 4.5

5.Math.min( , ) : 計算最小值

System.out.println(Math.min(2.3, 4.5));// 2.3

6.Math.abs() : 取絕對值

System.out.println(Math.abs(-10.4)); // 10.4 System.out.println(Math.abs(10.1)); // 10.1

7.Math.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 System.out.println(Math.ceil(-1.7)); // -1.0

8.Math.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

9.Math.rint(): 四舍五入,返回double值。注意.5的時候會取偶數(shù)

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

10.Math.round(): 四舍五入,float時返回int值,double時返回long值

System.out.println(Math.round(10.1)); // 10 System.out.println(Math.round(10.5)); // 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

11.Math.random(): 取得一個[0, 1)范圍內(nèi)的隨機數(shù)

System.out.println(Math.random()); // [0, 1)的double類型的數(shù) System.out.println(Math.random() * 2);//[0, 2)的double類型的數(shù) System.out.println(Math.random() * 2 + 1);// [1, 3)的double類型的數(shù)

12.π

System.out.println(Math.PI);//3.141592653589793

總結(jié)

以上是生活随笔為你收集整理的【蓝桥杯Java_C组·从零开始卷】第六节(一)、Java常用数学函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。