- java.lang.Math:
- (1)public static int abs(int a)求绝对值
- (2)public static double ceil(double a):向上取整,返回的是double
- (3)public static double floor(double a):向下取整:返回的是double
- (4)public static long round(double a) :四舍五入,返回的是long
- (5)public static double sqrt(double a) :求平方根
- (6)public static double random():求随机值[0,1)
- (7)public static double pow(double a,double b):求a的b次幂
- (8)public static int max(int a,int b):求a和b的最大值
- (9)public static int min(int a,int b):求a和b的最小值
- (10)public static final double PI:常量π
public class TestMath {
public static void main(String[] args) {
System.out.println(Math.ceil(2.2));
System.out.println(Math.floor(2.2));
System.out.println(Math.round(2.2));
System.out.println(Math.ceil(2.6));
System.out.println(Math.floor(2.6));
System.out.println(Math.round(2.6));
int num = (int) (Math.random() * 10);
int mi = (int) Math.pow(2, 3);
System.out.println(Math.max(4, 6));
System.out.println(Math.PI);
}
}