Java 中的 StrictMath 类有什么用?\
javaobject oriented programmingprogramming更新于 2025/9/19 7:08:17
java.lang.StrictMath 是一个 final 类,它是 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
相关文章
有用资源
java 参考教程 - 该教程包含有关 java 的更多信息:https://www.cainiaomax.com/java/

