Math

 1 package test;
 2 
 3 /*
 4  *Math:数学运算
 5  * 成员变量
 6  * PI  E 
 7  * 
 8  * 成员方法
 9  *         public static int abs(int a) 绝对值
10  *         public static double ceil(double a)  向上取整
11  *         public static double floor(double a) 向下取整
12  *         public static  int max(int a,int b) 
13  *         public static int min (int a,int b)
14  *         public static double pow(double a,double b)  a的b次幂
15  *         public static double random(); [0.0-1.0)
16  *         public static int round(float)  参数为double   四舍五入
17  *         public static double sqrt(double a)  正平方根
18  *         
19  * */
20 
21 public class Test01 {
22     public static void main(String[] args) {
23         System.out.println(Math.PI);
24         System.out.println(Math.E);
25         
26         //abs
27         System.out.println(Math.abs(-10));
28         //ceil
29         System.out.println(Math.ceil(12.34));
30         //floor
31         System.out.println(Math.floor(12.34));
32         //max
33         System.out.println(Math.max(12,33));
34         System.out.println(Math.max(12, Math.max(14, 44))); //方法嵌套调用
35         //pow
36         System.out.println(Math.pow(2,3));
37         //round
38         System.out.println(Math.round(12.63));
39         System.out.println(Math.round(12.11));
40         //sqrt
41         System.out.println(Math.sqrt(4));
42     }
43 }
 1 package test;
 2 
 3 /*
 4  * 获取任意区间的随机数
 5  * */
 6 
 7 public class Test01 {
 8     public static void main(String[] args) {
 9         for(int i=0;i<100;i++){
10             System.out.println(getRandom(12,15));
11             
12         }
13     }
14     
15     public static int getRandom(int start,int end){
16         int number=(int)(Math.random()*(end-start+1))+start;
17         
18         return number;
19     }
20 }

 

posted @ 2015-08-24 09:21  chengling  阅读(209)  评论(0编辑  收藏  举报