Math类:
常用成员方法:
public static int abs(int a) --------------------------------------- 绝对值
public static double ceil(double a) --------------------------- 向上取整
public static double floor(double a) ------------------------- 向下取整
public static double pow(double a,double b) -------------- 求a的b次方
public static double random() -------------------------------- 随机数: [0-1)
public static int round(float a) ------------------------------- 四舍五入,取整
public static double sqrt(double a) ------------------------- 求算数平方根
注:更多方法详见API文档
public class MathDemo01 {
public static void main(String[] args) {
System.out.println(Math.PI);
System.out.println(Math.E);
System.out.println(Math.abs(-12)); //绝对值
System.out.println(Math.ceil(15.1)); //向上取整
System.out.println(Math.floor(15.3)); //向下取整
System.out.println(Math.pow(10,2)); //10的2次方
System.out.println(Math.random()); //返回[0,1)的随机数
System.out.println(Math.round(10.4)); //四舍五入
System.out.println(Math.sqrt(9)); //算术平方根
}
}