16_Math
Math样式:
//1.获取圆周率π double pi = Math.PI; System.out.println(pi);//3.141592653589793 //2.获取绝对值 abs 结果都是正值 double abs = Math.abs(-5.5); System.out.println(abs); //3. 天花板、地板砖 // ceil(double d) 结果值比参数大的最小整数的double值(往上取整) double ceil = Math.ceil(-3.4); System.out.println(ceil); //-3.0 // floor (double d)结果值比参数小的最大整数的double值(往下取整) double floor = Math.floor(-3.9); System.out.println(floor);//-4 //4.max(double a,double b)和 min(double a,double b) double max = Math.max(3.9,5.4); System.out.println(max);//5.4 double min = Math.min(3.9,5.4); System.out.println(min);//3.9 //5.pow(a,b)获取a的b次幂的值 a^b --> 2^3 =2*2*2=8 double pow = Math.pow(2, 3); System.out.println(pow);//8.0 //6. round(double a) 正数四舍五入 负数六舍五入 long round = Math.round(3.5);// -3.5 -3.6 System.out.println(round);//4 -4 -3 //7.random() 获取随机数 [0.0,1.0)小数 double random = Math.random(); System.out.println(random); //获取[5,100] int ranNum = (int)(Math.random()*(100-5+1))+5; System.out.println(ranNum);