首頁  >  文章  >  Java  >  StrictMath類別在Java中的用途是什麼?

StrictMath類別在Java中的用途是什麼?

PHPz
PHPz轉載
2023-09-12 21:21:021319瀏覽

StrictMath類別在Java中的用途是什麼?

java.lang.StrictMath是一個最終類,它是Object類別的子類別。 StrictMath 類別包含用於執行基本數字運算的方法,例如初等指數、對數、平方根三角函數。我們不需要為StrictMath類別建立實例,因為StrictMath類別中的所有方法都是靜態方法。 StrictMath類別的重要方法有abs()、acos()、asin()、atan()、ceil()、floor()、log()、max()、min()、pow()、 random()、 round() 等

語法

public final class StrictMath extends Object

範例

public class StrictMathTest {
   public static void main(String args[]) {
      System.out.println("Absolute Value: " + StrictMath.abs(-100.50));
      System.out.println("Ceil Value : " + StrictMath.ceil(100.55));
      System.out.println("Floor Value : " + StrictMath.floor(100.55));
      System.out.println("Maximum Value : " + StrictMath.max(100,200));
      System.out.println("Minimum Value : " + StrictMath.min(100,200));
      System.out.println("Random Value : " + StrictMath.random());
      System.out.println("Round Value: " + StrictMath.round(100.75));
      System.out.println("Square Root Value : " + StrictMath.sqrt(2));
      System.out.println("PI Value: " + StrictMath.PI);
      System.out.println("Log Value: " + StrictMath.log(10.55));
   }
}

輸出

Absolute Value: 100.5
Ceil Value : 101.0
Floor Value : 100.0
Maximum Value : 200
Minimum Value : 100
Random Value : 0.22227639516105102
Round Value: 101
Square Root Value : 1.4142135623730951
PI Value: 3.141592653589793
Log Value: 2.3561258599220753

以上是StrictMath類別在Java中的用途是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除