Math类的使用
A:Math 类包含用于执行基本数学运算的方法。数学操作常用的类。
B:Math类的构造方法被private,无法创建对象,也就无法通过对象来访问Math类中的成员
C:Math类中所有的成员都被静态修饰,因此我们可以直接通过类名访问。
常用的一些数学运算方法:
①static double PI : 圆周率的值
例如:Math.PI
②static double abs(double a) : 返回绝对值
例如:Math.abs(-10)
③static double ceil(double a) : 天花板 向上取整
例如:Math.ceil(1.2)
④static double floor(double a) : 地板 向下取整
例如:Math.floor(1.2)
⑤static long round(double a) :四舍五入
例如:Math.round(1.2)
⑥static double max(double a, double b) :取最大值
例如:Math.max(3, 4)
⑦static double pow(double a, double b) :返回第一个参数的第二个参数次幂
例如:Math.pow(3, 2)
⑧static double random() :返回一个随机数,大于0且小于1
例如:Math.random()