java进阶 - Math -abs取绝对值 -ceil向上取整 -ceil向下取整 -四舍五入round -max返回最大值 -max返回最小值 -random随机数39
package com.cyjt97.M; public class mathM { public static void main(String[] args) { // abs取绝对值 System.out.println(Math.abs(-123));//123 System.out.println(Math.abs(-12.3));//12.3 System.out.println("--------------------------------"); // ceil向上取整 System.out.println(Math.ceil(12.3));//13.0 System.out.println(Math.ceil(12.9));//13.0 System.out.println(Math.ceil(12.1));//13.0 System.out.println("--------------------------------"); // ceil向下取整 System.out.println(Math.floor(12.3));//12.0 System.out.println(Math.floor(12.9));//12.0 System.out.println(Math.floor(12.1));//12.0 System.out.println("--------------------------------"); // 四舍五入round System.out.println(Math.round(3.4));//3 System.out.println(Math.round(3.5));//4 System.out.println(Math.round(3.6));//4 System.out.println("--------------------------------"); // max返回最大值 System.out.println(Math.max(10, 30));//30 System.out.println(Math.max(10, 20));//20 System.out.println("--------------------------------"); // max返回最小值 System.out.println(Math.min(10, 20));//10 System.out.println("--------------------------------"); // pow返回a的b次幂 System.out.println(Math.pow(10, 10)); System.out.println("--------------------------------"); // random随机数 System.out.println(Math.random()); } }
代码改变了我们,也改变了世界