1 package org.hanqi.array;
 2 
 3 import java.util.Random;
 4 
 5 public class BaoZhuang {
 6 
 7     public static void main(String[] args) {
 8         
 9         //包装类
10         Long l = new Long(100);
11         //把字符串转成数值
12         Long l1 = new Long("1000");        
13         String str = 1000 + "";
14         //从包装类转成基本数据类型
15         long l2 = l1.longValue();
16         System.out.println("l2="+l2);
17         
18         long l3 = Long.parseLong("1200");
19         System.out.println(l3);
20         
21         //int
22         Integer i = new Integer("100");
23         Integer.parseInt("100");
24         
25         //float
26         Float f = new Float("123.45");
27         Float.parseFloat("123.45");
28         
29         //double
30         Double d = new Double("12345.67");
31         Double.parseDouble("123.78");
32         
33         //boolean
34         Boolean b = new Boolean("ture");
35         System.out.println(b.booleanValue());
36         
37         //数学工具类
38         System.out.println(Math.PI);
39         //四舍五入
40         System.out.println(Math.round(1234.46789));
41         double de = 1234.5678;
42         System.out.println(Math.round(de));
43         //保留小数点后2位
44         System.out.println(Math.round(de*100)/100.0);
45         //舍去小数点后的数字
46         //下限值:小于或等于它的最大整数
47         System.out.println(Math.floor(de));
48         //上限值:大于或等于它的最小整数
49         double de1 = 1234.06;
50         System.out.println(Math.ceil(de1));
51         //随机数 0-1 之间
52         System.out.println(Math.random());
53         System.out.println(Math.random());
54         System.out.println(Math.random());
55         System.out.println(Math.random());
56         
57         System.out.println();
58         
59         Random r = new Random();
60         //随机数种子
61         //伪随机数
62         //根据种子计算
63         //r = new Random(1);
64         //默认使用时间做种子
65         for(int m=0;m<10;m++)
66         {
67             System.out.println(r.nextInt(100));//限定范围的随机
68         }
69     }
70 }

运行结果为:

相关思维导图: