Math基本用法

package com.javabin.interface_;

/**
 * Copyright (C), 2018-2021, Mr.Lin
 * Author: Mr.Lin
 * Date: 2021/11/19 16:54
 * FileName: MathMethod
 * Description:
 */
public class MathMethod {
    public static void main(String[] args) {
        //1.abs 绝对值
        int abs =Math.abs(-12);
        System.out.println(abs);
        //2.pow 求幂
        double pow =Math.pow(3,3);//3的3次方
        System.out.println(pow);
        //3.ceil 向上取整,返回>=该参数的最小整数(double)
        double ceil = Math.ceil(3.9999);
        System.out.println(ceil);
        //4.floor向下取整,返回<=该参数的最大整数(double)
        double floor = Math.floor(-4.9999);
        System.out.println(floor);
        //round 四舍五入
        long round = Math.round(-5.3);
        System.out.println(round);
        //sqrt 求开放
        double sqrt = Math.sqrt(81.0);
        System.out.println(sqrt);
        //random 求随机数
        //返回0<= x <1 的随机小数
        //求a-b之间的随机数(a,b均为整数)
        int a=4300,b=4399;
        for (int i = 0; i <10 ; i++) {
            System.out.println((int)(Math.random()*(b-a+1)+a));
        }
    }
}

 

posted @ 2021-11-19 17:22  骄傲的林先生  阅读(110)  评论(0)    收藏  举报