一、Math类:数学类。
1、Math类是final类,不能被继承;
2、Math中所有的方法和成员都是静态的(static),可以通过类名.方法名或类名.属性名的方式来调用;
3、Math类中包括对整数或小数进行操作的各种方法;
二、Math类中的常用属性和方法:
1、Math.PI 得到3.141592653589793;
2、long Math.round(double):对双精度浮点数四舍五入取整数,得到长整型;
例:System.out.println(Math.round(6.8)); // 输出结果:7
3、int Math.round(float):对单精度浮点数四舍五入取整数,得到整型;
例:System.out.println(Math.round(6.8f)); // 输出结果:7
4、Math.ceil(double):得到大于参数的最小值;
例:System.out.println(Math.ceil(6.1)); // 输出结果:7.0
5、Math.floor(double):得到小于参数的最大值;
例:System.out.println(Math.floor(7.8)); //输出结果:7.0
6、Math.max(num1,num2):得到num1和num2两个数中较大的数;
例:System.out.println(Math.max(3, 7)); // 输出结果:7
7、Math.min(num1,num2):得到num1和num2两个数中较小的数;
例:System.out.println(Math.min(3, 7)); // 输出结果:3