1、API介绍

2、属性

public class Demo5_Math {
public static void main(String[] args) {
//属性
System.out.println(Math.E);//2.718281828459045
System.out.println(Math.PI);//3.141592653589793
}
}
3、功能方法


public class Demo5_Math {
public static void main(String[] args) {
//abs() 求绝对值
int abs = Math.abs(10);
System.out.println(abs);//10
int abs1 = Math.abs(-100);
System.out.println(abs1);//100
//max 求最大值
int max = Math.max(10, 50);
System.out.println(max);//50
//min 求最小值
double min = Math.min(2.3, 0.5);
System.out.println(min);//0.5
//random() 求随机值 [0 1)
double random = Math.random();
System.out.println(random);//0.3278848432155409
//面试题:生成一个1~10之间随机数
int i = (int) ((Math.random() * 10) + 1);
System.out.println(i);
//ceil() 向上取整
double ceil = Math.ceil(2.3);
System.out.println(ceil);//3.0
//floor() 向下取整
double floor = Math.floor(3.9);
System.out.println(floor);//3.0
//round() 四舍五入
long round = Math.round(2.3);
System.out.println(round);//2
//method_属性();
}
}
889

被折叠的 条评论
为什么被折叠?



