Math类

Math

  public final class Math extends Object

  01.就是一个算术类,是final修饰

  02.除了构造方法之外所有的方法都是静态方法,方便我们使用

常用方法:

public static void main(String[] args) {
        System.out.println("向上取整==》" + Math.ceil(3.1));
        System.out.println("向下取整==》" + Math.floor(3.99));
        System.out.println("四舍五入==》" + Math.round(3.1));
        System.out.println("四舍五入==》" + Math.round(3.9));
        System.out.println("绝对值==》" + Math.abs(3.1));
        System.out.println("绝对值==》" + Math.abs(-3.1));
        System.out.println("最大值==》" + Math.max(3.1, 2.5));
        System.out.println("最小值==》" + Math.min(3.1, 2.5));
        /**
         *  随机数 0-1 但是不包含1
            public static double random() {
              Random rnd = randomNumberGenerator;
              if (rnd == null) 
           rnd = initRNG();    return rnd.nextDouble(); }
*/ System.out.println(Math.random()); }
原文地址:https://www.cnblogs.com/ak666/p/8109137.html