1 package cn.mantishell.day08.demo04; 2 3 /** 4 * java.util.Math类是数学相关的工具类,里面提供类大量的静态方法,完成与数学运算相关的操作 5 * 6 * public static double abs(double num);获取绝对值 7 * public static double ceil(double num);向上取整 8 * public static double floor(double num);向下取整 9 * public static long round(double num);四舍五入 10 */ 11 public class Demo03Math { 12 public static void main(String[] args) { 13 //获取绝对值 14 System.out.println(Math.abs(-2.5));//2.5 15 //向上取整 16 System.out.println(Math.ceil(3.9));//4.0 17 System.out.println(Math.ceil(3.1));//4.0 18 System.out.println(Math.ceil(3.0));//3.0 19 20 System.out.println(Math.floor(10.9)); 21 22 System.out.println(Math.round(2.6)); 23 } 24 }