1 package shuzi;
2
3 import java.text. DecimalFormat;
4 import java.math.BigInteger;
5 import java.math.BigDecimal;
6 import java.util.Random;
7 public class ssssss {
8
9 public static void main(String[] args) {
10
11 int i =123;
12
13 long l = i;
14
15 int intl = (int)l;
16
17 //数字包装类
18
19 Integer ig = new Integer("2");
20
21 int int3 = ig.intValue();
22
23 System.out.println("ig =" +int3);
24
25 //数据转换的静态方法,常用方法
26
27 Integer.parseInt("123"); //int型
28
29 int int5=Integer.MAX_VALUE;
30 int int6=Integer.MIN_VALUE;
31
32 System.out.println("Integer.MAX_VALUE=" +int5);
33 System.out.println("Integer.MIN_VALUE="+int6);
34
35 Long long1=new Long("222");
36
37 Long.parseLong("1234568"); //long型
38 System.out.println("long1="+long1);
39 long lon1 =Long.parseLong("2222222");
40 System.out.println("lon1="+lon1);
41
42
43 double dou1= Double.parseDouble("1234.111"); //double型
44 System.out.println("dou1="+dou1);
45 double dou2= Double.parseDouble("1234");
46 System.out.println("dou2="+dou2);
47
48 //字符串(忽略大小写)等于"true",转成true,其他全转成false
49
50 boolean t = Boolean.parseBoolean("tRUe"); // boolean型
51 System.out.println("t="+t);
52
53 //数字格式化 随机数
54 //0 - 数字,自动显示0
55 //# - 数字,不自动补0,
56
57 DecimalFormat df =new DecimalFormat("0000.00");
58
59 System.out.println("123.456=" +df.format(123.456));
60
61 df.applyPattern("#.##");
62
63 System.out.println("123.456 #.##=" +df.format(123.456));
64 System.out.println("5,123,789.456=" +df.format(123.456));
65 df.applyPattern("#.####");
66
67 System.out.println("123.456 =" +df.format(123.456));
68
69 df.applyPattern("#,###,###.##");
70 System.out.println("5,123,789.456=" +df.format(12333333.456));
71
72 df.applyPattern("##.#%");
73
74 System.out.println("0.78="+df.format(0.7863));
75
76 df.applyPattern("##%");
77
78 System.out.println("0.78="+df.format(0.786));
79
80 df.applyPattern("##.#%");
81
82 System.out.println("0.78="+((0.78*100)+"%") +" "+ df.format(0.7863));
83
84 //数学运算
85
86 System.out.println(""+Math.PI); //π的表示
87
88 //取整函数
89
90 double dd =123.45;
91
92 System.out.println("ceil="+Math.ceil(dd)); //大于123.45的最小整数,小数的上限值
93
94 System.out.println("floor="+Math.floor(dd)); //小于123.45的最小整数,小数的下限值
95
96 //四舍五入
97
98 System.out.println("round"+Math.round(dd));
99
100 //随机数 0-1之间的数字,随机数种子,默认使用计算机的当前时间做种子
101 for(int a =0;a<10;a++)
102 {
103 System.out.println("随机数"+Math.random()); //用for循环随机产生10组数字
104 }
105 for(int b =0;b<10;b++)
106 {
107 System.out.println("随机数="+Math.ceil(Math.random()*100));
108 }
109 //实例化,制定种子
110 Random rm = new Random(123);
111
112 for (int j =0; j<10;j++)
113 {
114 System.out.println("Random随机数="+rm.nextDouble());
115
116 }
117 for (int v =0; v<10;v++)
118 {
119 System.out.println("Random随机数="+rm.nextInt(10));
120 }
121
122 BigInteger gi = new BigInteger ("1234566543312");
123 BigDecimal bb = new BigDecimal("12345.1112234");
124
125
126
127 }
128
129 }