首页 > Java > java教程 > 正文

StrictMath类在Java中的用途是什么?

PHPz
发布: 2023-09-12 21:21:02
转载
1348 人浏览过

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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!