赞
踩
System.out.println(Math.abs(-100)); //100 System.out.println(Math.min(100, 200)); //100 System.out.println(Math.max(100, 200)); //200 //四舍五入 System.out.println(Math.round(1.5)); //2 System.out.println(Math.round(-1.5)); //-1 //返回最接近的整数(double型) System.out.println(Math.rint(1.5)); //2.0 System.out.println(Math.rint(-1.5)); //-2.0 //向下取整 System.out.println(Math.floor(3.5)); //3 System.out.println(Math.floor(-3.5)); //-4 //向上取整 System.out.println(Math.ceil(3.5)); //4 System.out.println(Math.ceil(-3.5)); //-3 //int或long型数值相加 System.out.println(Math.addExact(2, 8)); //10 System.out.println(Math.addExact(2147483647, 3)); //溢出int或long会抛出异常:Exception in thread "main" java.lang.ArithmeticException: integer overflow //返回值递减1,溢出抛异常 System.out.println(Math.decrementExact(8)); //7 System.out.println(Math.incrementExact(8)); //9 //exp() System.out.println(Math.exp(1)); //2.718281828459045 //除法,向下取整 System.out.println(Math.floorDiv(8,3)); //2 //返回余数 System.out.println(Math.floorMod(8,3)); //2 //幂 System.out.println(Math.pow(8,2)); //64 //[0,1)的double随机数 System.out.println(Math.random()); //数学常数 System.out.println(Math.PI); //3.141592653589793
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。