课堂所讲整理:包装&工具类

 package org.hanqi.array;

 import java.util.Random;

 public class BaoZhuang {

     public static void main(String[] args) {

         //包装类
Long l = new Long(100);
//把字符串转成数值
Long l1 = new Long("1000");
String str = 1000 + "";
//从包装类转成基本数据类型
long l2 = l1.longValue();
System.out.println("l2="+l2); long l3 = Long.parseLong("1200");
System.out.println(l3); //int
Integer i = new Integer("100");
Integer.parseInt("100"); //float
Float f = new Float("123.45");
Float.parseFloat("123.45"); //double
Double d = new Double("12345.67");
Double.parseDouble("123.78"); //boolean
Boolean b = new Boolean("ture");
System.out.println(b.booleanValue()); //数学工具类
System.out.println(Math.PI);
//四舍五入
System.out.println(Math.round(1234.46789));
double de = 1234.5678;
System.out.println(Math.round(de));
//保留小数点后2位
System.out.println(Math.round(de*100)/100.0);
//舍去小数点后的数字
//下限值:小于或等于它的最大整数
System.out.println(Math.floor(de));
//上限值:大于或等于它的最小整数
double de1 = 1234.06;
System.out.println(Math.ceil(de1));
//随机数 0-1 之间
System.out.println(Math.random());
System.out.println(Math.random());
System.out.println(Math.random());
System.out.println(Math.random()); System.out.println(); Random r = new Random();
//随机数种子
//伪随机数
//根据种子计算
//r = new Random(1);
//默认使用时间做种子
for(int m=0;m<10;m++)
{
System.out.println(r.nextInt(100));//限定范围的随机
}
}
}

运行结果为:

课堂所讲整理:包装&工具类

相关思维导图:

课堂所讲整理:包装&工具类

上一篇:HBase 官方文档中文版


下一篇:图解Java设计模式之设计模式面试题