zoukankan      html  css  js  c++  java
  • java===Math类

    package 常用类.Math;
    
    import java.util.Random;
    
    /**Math提供了操作数学运算的方法,都是静态的。
     * 常用方法:Math.abs();返回绝对值
     *        Math.ceil();返回大于参数的最小整数
     *        Math.floor();返回小于参数的最大整数
     *        Math.round();返回四舍五入的整数
     *        Math.random();返回一个伪随机数double类型,在0.0到1.0之间;注意要想有更多操作建议直接使用Random类实例来调用nextInt方法获取随机数
     *        Math.pow(10,2);返回10的2次幂
     *        Math.max(a,b);返回较大的一个数
     *        */
    public class MathDemo {
    
        public static void main(String[] args) {
            //demo_1(12.56);
            demo_2();
    //        double d1=Math.max(12.13, 14.15);
    //        System.out.println(d1);
    //        double d2 =Math.pow(10, 2);//10的2次幂;
    //        System.out.println(d2);
    
        }
    
        private static void demo_2() {
            Random r1 = new Random();
            for (int i = 0; ; i++) {
                double d1 =Math.ceil(Math.random()*6);
                //double d2 =(int)(r1.nextDouble()*6+1);
                //int d2 =r1.nextInt()*6+1;
                System.out.println(d1);
                if(d1==1)
                    return;
                
            }
        }
    
        public static void demo_1(double d) {
            double d1 = Math.ceil(d);
            double d2 = Math.floor(d);
            double d3 = Math.round(d);
            System.out.println(d1);
            System.out.println(d2);
            System.out.println(d3);
        }
    
    }
  • 相关阅读:
    诊断
    HIS内号码说明
    ASP.NET Page life cycle
    ASP.NET Simple page life cycle
    java多线程
    ibatis sqlmap
    cglib和asm
    利用ant编译maven项目
    Spring Cache与Tair结合
    USACO 1.2 MILKING COWS
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/6753969.html
Copyright © 2011-2022 走看看