Math类

Math类作为常用类中的一个,一般情况下我们用的不是特别多,除非你是在特殊领域

若要用的话还是查看下api比较靠谱

 1 public class MathTest {
 2     public static void main(String[] args) {
 3         //取绝对值
 4         System.out.println(Math.abs(-1));                        //1
 5         //开方
 6         System.out.println(Math.sqrt(9));                        //3.0
 7         //向上取整
 8         System.out.println(Math.ceil(3.14));                     //4.0
 9         //向下取整
10         System.out.println(Math.floor(3.14));                    //3.0
11         /**
12          * 生成[a,b)之间的任意整数
13          *   公式:int num = (int)(Math.random()*(b-a+1)+a);
14          */
15         //生成0-10之间的任意整数
16         int a = (int)(10*Math.random());
17         System.out.println(a);                                   //2
18 
19     }
20 }
原文地址:https://www.cnblogs.com/lyc-code/p/12562424.html