JAVA常见类(七) Math类

Math类

math类是用于数学计算的类。在使用是直接math.方法或math.静态变量来使用,不需要创建对象。

一、静态变量

static double E      比其他任何一个都更接近 e ,自然对数的基数。

static double PI     比任何其他的更接近 pi ,圆周长与其直径的比率。

二、常用方法

public static int abs(int a):绝对值

 public static double ceil(double a):向上取整

 public static double floor(double a):向下取整

 public static int round(float a) 四舍五入

 public static int max(int a,int b):最大值 

 public static int min(int a,int b):最小值

 public static double pow(double a,double b):a的b次幂

 public static double random():随机数 [0.0,1.0)

 public static double sqrt(double a):正平方根

猜你喜欢

转载自blog.csdn.net/ytasdfg/article/details/81081554