您的位置:首页 > 其它

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

2016-01-14 22:56 253 查看
⑩数字处理类
取整: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

double d1 =123.1;

Double dd=new Double("123.45");//由字符串转成Double
double dv=dd.doubleValue();//从包装类转成基本数据类型
System.out.println("Double="+dd+"double="+dv);

Double df=new Double(1234.67);
String ds=df.toString();//包装类转成字符串
System.out.println(ds);

Float f=new Float("123.45");
int g=f.intValue();
System.out.println("int值"+g);

Long l=new Long(123);
float sss=l.floatValue();
System.out.println("输出"+sss);

Integer it=new Integer(12345);
int iii=it.intValue();//int的包装类
int ii=Integer.valueOf("1234").intValue();
System.out.println("输出"+iii);
//布尔型
Boolean b=new Boolean("True");
boolean y=b.booleanValue();
System.out.println("输出"+y);


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: