Java 之 Math类

    // Math测试方法
    public static void MathTestMethod(){
        //向下取整
        int param_1 = (int)Math.floor(3.14f); //3
        //向上取整
        int param_2 = (int)Math.ceil(3.14f); //4
        //四舍五入
        int param_3 = (int)Math.round(3.49f); //3
        int param_4 = (int)Math.round(3.5f); //4
        //0-1 包含0 不包含1
        double param_5 = Math.random(); //0.7761912318494582
        //0-100 包含0 不包含100
        int param_6 = (int)(Math.random()*100); //54
        // 随机四位数
        int param_7 = (int)(Math.random()*9000 + 1000);
        System.out.println(param_7);
    }

其他使用方法,请参考API文档

posted @ 2020-08-02 22:13  gygtech  Views(155)  Comments(0Edit  收藏  举报