2016/1/14 数字类处理 包装类

⑩数字处理类
取整:1,四舍五入,格式Math.round(浮点数)
   2,取下限值,格式 Math.floor(浮点数)
     3,取上限值,格式Math.ceil(浮点数)

生成随机数 1,Math.random()静态方法。介于0和1之间的小数
               2,Random类 实例化Random Random x =new Random()
                                  Random x=new Random(随机数种子)
               产生随机数 一般形式 int r(注r为名称) = x.nextint();

                 nextint(最大值) 生成介于零和最大值间的随机数
                 限定了范围 范围越小 越容易重复

⑪包装类 double Double 对象名=new Double("字符串");
                 对象名.doubleValue() 转成基本数据类型

           integer Integer 对象名=new Integer(12345);
             int iii=it.intValue();

Boolean Boolean 对象名=new Boolean("字符串") 分两种情况
一,字符串为不区分大小写的true 则转为true 二,其他都为false

 1 double d1 =123.1;
 2         
 3         Double dd=new Double("123.45");//由字符串转成Double
 4         double dv=dd.doubleValue();//从包装类转成基本数据类型
 5         System.out.println("Double="+dd+"double="+dv);
 6         
 7         Double df=new Double(1234.67);
 8         String ds=df.toString();//包装类转成字符串  
 9         System.out.println(ds);
10         
11         Float f=new Float("123.45");
12         int g=f.intValue();
13         System.out.println("int值"+g);
14         
15         Long l=new Long(123);
16         float sss=l.floatValue();
17         System.out.println("输出"+sss);
18         
19         Integer it=new Integer(12345);
20         int iii=it.intValue();//int的包装类 
21         int ii=Integer.valueOf("1234").intValue();
22         System.out.println("输出"+iii);
23         //布尔型 
24         Boolean b=new Boolean("True");
25         boolean y=b.booleanValue();
26         System.out.println("输出"+y);
View Code

posted on 2016-01-14 22:56  一棵树2016  阅读(219)  评论(0编辑  收藏  举报