Math类是数学类,主要用里面的方法:格式: Math.方法名
    image.png

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