常用的Math.方法如下:
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 double pow(double a,double b) 求a的b次方
public static double random() 产生随机值[0,1)
public class MATH {
public static void main(String[] args) {
/*
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 double pow(double a,double b) 求a的b次方
public static double random() 产生随机值[0,1)
*/
System.out.println("求绝对值:" + Math.abs(-8888));
System.out.println("向上取整:" + Math.ceil(3.33333));
System.out.println("向下取整:" + Math.floor(9.99999));
System.out.println("四舍五入:" + Math.round(4.4));
System.out.println("四舍五入:" + Math.round(4.5));
System.out.println("获取较大值:" + Math.max(5,9));
System.out.println("求a的b次方:" + Math.pow(2,3));
System.out.println("产生随机值[0,1):" + Math.random());
}
}