Math类
概述
Math类包含执行基本数字运算的方法,如基本指数,对数,平方根和三角函数。
成员方法
static double max(double a, double b)
//返回两个 double值中的较大值。
static double min(double a, double b)
//返回两个 double的较小值。
static int abs(int a)
//求绝对值(有double,float,long的重载)
static double pow(double a, double b)
//求a的b次方
static double sqrt(double a)
//平方根
取整
static double ceil(double a) //向上取整
//返回大于或等于参数的最小double值,等于一个数学整数。
static double floor(double a) //向下取整
//返回小于或等于参数的最大double值,等于一个数学整数。
static long round(double a)
//返回参数中最接近的 long round为四舍五入,是往大的方向近似
static int round(float a)
//返回参数中最接近的 int
round()方法
//四舍五入,五入是往大的近似;注意参数和返回值的类型是不同的
System.out.println(Math.round(-11.5)); //-11
System.out.println(Math.round(11.5)); //12