Math类是数学类,主要用里面的方法:格式: Math.方法名
package com.itheima.d12_math;
import com.itheima.d4_polymorphic_test.Mouse;
public class MathDemo {
public static void main(String[] args) {
// 1.取绝对值:返回正数
System.out.println(Math.abs(10));
System.out.println(Math.abs(-10.3));
// 2.向上取整 : 5
System.out.println(Math.ceil(4.00000001)); // 5.0 不会四舍五入,直接向上取整
// 3. 向下取整 :4
System.out.println(Math.floor(4.9999999)); // 5.0
// 4.求指数方
System.out.println(Math.pow(2,3));
// 5. 四舍五入法 10
System.out.println(Math.round(4.9999)); // 4
System.out.println(4.500001); // 5
// 这里的random是Math类的方法 计算机中都是包前不包后(包括0.0,不包括1.0)
System.out.println(Math.random()); // 0.0~1.0
}
}