JAVA常用API中的Math

int abs(int a)  // 返回参数的绝对值
double ceil(double a)  // 向上取整
double floor(double a)  // 向下取整
int round(float a)  // 四舍五入
int max(int a,int b)  // 返回两个int值中的较大值
int min(int a,int b)  // 返回两个int值中的较小值
double pow(double a,double e)  // 返回a的b次幂的值
double random()  // 返回值为double的正值,[0.0,1.0}
package com.shengda.Demo1Math;

public class MathDemo {
    public static void main(String[] args) {
        // public static int abs(int a)  // 返回参数的绝对值
        int abs = Math.abs(10);
        System.out.println(abs);
        // public static double ceil(double a)  // 向上取整
        double ceil = Math.ceil(10.1);
        System.out.println(ceil);
        // public static double floor(double a)  // 向下取整
        double floor = Math.floor(10.9);
        System.out.println(floor);
        // public static int round(float a)  // 四舍五入
        long round = Math.round(10.2);
        System.out.println(round);
        // public static int max(int a,int b)  // 返回两个int值中的较大值
        int max = Math.max(10, 20);
        System.out.println(max);
        // public static int min(int a,int b)  // 返回两个int值中的较小值
        int min = Math.min(10, 20);
        System.out.println(min);
        // public static double pow(double a,double e)  // 返回a的b次幂的值
        double pow = Math.pow(2, 3);
        System.out.println(pow);
        // public static double random()  // 返回值为double的正值,[0.0,1.0}
        for (int i = 0;i<10;i++) {
            double random = Math.random();
            System.out.println(random);
        }
    }
}

输出的结果
10
11.0
10.0
10
20
10
8.0
0.6979680131355988
0.11751067605032861
0.622410557056649
0.5537912178041239
0.6488909321701665
0.13247958110740166
0.9506927470911505
0.8569465736712201
0.5989096287389925
0.31865073397813903

进程已结束,退出代码为 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值