常用API—Math

Math

  • Math类概述
    • math包含执行基本数字运算的方法
  • Math中方法发调用方式
    • Math类中无构造方法,但内部的方法都是静态的,可以通过 类名.进行调用
  • Math 类的常用方法
方法名说明
public static int abs(int a)返回参数的绝对值
public static double ceil(double a)返回大于或等于参数的最小double值,等于一个整数
public static double floor(double a)返回小于或等于参数的最大double值,等于一个整数
public static int round(float a)按照四舍五入返回最近接参数的int
public static int max(int a,int b)返回两个int值中的较大值
public static int min(int a,int b)返回两个int值中的较小值
public static double pow返回啊的b次幂的值
public static double random()返回值为double的正值,[0.0,1.0]
public class MathDemo {
    public static void main(String[] args) {

//	public static int abs(int a)	返回参数的绝对值
        System.out.println(Math.abs(88));  //输出88
        System.out.println(Math.abs(-88)); //输出88
//	public static double ceil(double a)	返回大于或等于参数的最小double值,等于一个整数
        System.out.println(Math.ceil(88.4)); //输出89
        System.out.println(Math.ceil(88.8)); //输出89
//	public static double floor(double a)	返回小于或等于参数的最大double值,等于一个整数
        System.out.println(Math.floor(88.1));//输出88
        System.out.println(Math.floor(88.9));//输出88
//	public static int round(float a)	按照四舍五入返回最近接参数的int
        System.out.println(Math.round(88.1f));//输出88
        System.out.println(Math.round(88.9f));//输出89
//	public static int max(int a,int b)	返回两个int值中的较大值
        System.out.println(Math.max(88,89));//输出89
//	public static int min(int a,int b)	返回两个int值中的较小值
        System.out.println(Math.min(88,89));//输出88
//	public static double pow	返回啊的b次幂的值
        System.out.println(Math.pow(2,4));//输出2的4次幂 16
//	public static double random()	返回值为double的正值,[0.0,1.0]
        System.out.println(Math.random());//随机0.0~1.0之间的double值(不包括0和1)

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值