zoukankan      html  css  js  c++  java
  • 数 函数类 Math类

    Math样式:

    复制代码
        //1.获取圆周率π
            double pi = Math.PI;
            System.out.println(pi);//3.141592653589793
            
        //2.获取绝对值 abs  结果都是正值
            double abs = Math.abs(-5.5);    
            System.out.println(abs);    
        //3.  天花板、地板砖    
        // ceil(double d)  结果值比参数大的最小整数的double值(往上取整)
            double ceil = Math.ceil(-3.4);
            System.out.println(ceil);  //-3.0
        //  floor (double d)结果值比参数小的最大整数的double值(往下取整)
            double floor = Math.floor(-3.9);
            System.out.println(floor);//-4
        //4.max(double a,double b)和 min(double a,double b)
            double max = Math.max(3.9,5.4);
            System.out.println(max);//5.4
            double min = Math.min(3.9,5.4);
            System.out.println(min);//3.9
        //5.pow(a,b)获取a的b次幂的值   a^b  -->  2^3 =2*2*2=8
            double pow = Math.pow(2, 3);
            System.out.println(pow);//8.0
        //6. round(double a) 正数四舍五入  负数六舍五入
            long round = Math.round(3.5);// -3.5  -3.6
            System.out.println(round);//4   -4     -3
        //7.random()  获取随机数  [0.0,1.0)小数
            double random = Math.random();
            System.out.println(random);
            //获取[5,100]
            int ranNum = (int)(Math.random()*(100-5+1))+5;
            System.out.println(ranNum);
  • 相关阅读:
    20190817-T1-LOJ6322「雅礼国庆 2017 Day6」Star Way To Heaven
    20190817-涪
    20190816-周期
    考试总结 模拟95
    考试总结 模拟94
    考试总结 模拟93
    考试总结 模拟92
    考试总结 模拟91
    考试总结 模拟90
    考试总结 模拟89
  • 原文地址:https://www.cnblogs.com/rosiness/p/13922959.html
Copyright © 2011-2022 走看看