zoukankan      html  css  js  c++  java
  • Java基本数学运算之Math类

    什么是Math类

    • Java操作数学运算相关的类
    • 构造函数被私有化,所以不允许创建对象
    • 都是静态方法,使用是直接类名.方法名

    常用API

    //计算平⽅根
    System.out.println(Math.sqrt(16));
    //计算⽴⽅根
     System.out.println(Math.cbrt(8));
     //两个数的最⼤,⽀持int, long, float,double
     System.out.println(Math.max(2.9,4.5));
     System.out.println(Math.min(2.9,4.5));
     //ceil向上取整,更⼤的值⽅向靠拢, 中⽂是天花板
     System.out.println(Math.ceil(19.7));
     System.out.println(Math.ceil(-20.1));
     //floor向下取整,更⼩的值⽅向靠拢,中⽂是地板意思
     System.out.println(Math.floor(19.7));
     System.out.println(Math.floor(-20.1));
     //随机数
     System.out.println(Math.random()); //⼩于1⼤于0的double类型的数
     //产⽣1到10的随机数,int⽅法进⾏转换它会去掉⼩数掉后⾯的数字即只获取整数部分,不是四舍
    五⼊
     int random=(int)(Math.random()*10+1);

    产生随机数:math.random(),结果在0-1

  • 相关阅读:
    关系型数据库与非关系型数据库
    项目技术点总结
    小程序项目开发总结
    小程序的生命周期
    ES6中的class 与prototype
    js中的深拷贝与浅拷贝
    DOM的构建与优化
    ES6中promise总结
    react服务端渲染
    vue服务端渲染
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13417364.html
Copyright © 2011-2022 走看看