Set,Map,包装类工具类
2016-03-11 20:54
225 查看
package Leidejihe; import java.util.Random; public class Baozhuanglei { public static void main(String[] args) { //包装类Long型 Long l=new Long(100); //用包装类把字符串转成数值 Long l1=new Long("1000"); // // String str=1000+"";//把1000转成字符串的 // System.out.println(str); System.out.println(l1); //从包装类转成基本数据类型 Long l2=l1.longValue(); System.out.println("l2="+l2); Long l3=Long.parseLong("12999"); System.out.println("直接转:Long.parseLong()"+l3); //int型 Integer i=new Integer("1000"); Integer.parseInt("100"); //float Float f=new Float("123.45"); Float.parseFloat("123.456"); //Double Double d=new Double("1234.567"); Double.parseDouble("123456.78"); //boolean型 Boolean b=new Boolean("aaaaa"); System.out.println(b.booleanValue()); Boolean b1=new Boolean("true"); System.out.println(b1); //数学工具类。Math不能实例化,全是静态的方法 System.out.println(Math.PI); //四舍五入 Math.round(1234.56); System.out.println(Math.round(1234.56)); double d1=12.345678; System.out.println("d1="+d1); System.out.println("d1四舍五入:"+Math.round(d1)); System.out.println("d1保留两位小数:"+Math.round(d1*100)/100.0);//转成double型 //去小数点取整:下限值,上限值。返回double型 System.out.println("舍去小数点,下限值:"+Math.floor(d1)); System.out.println("舍去小数点,上限值:"+Math.ceil(d1)); //随机数Random。 //random只产生0-1之间的数,要取0-100的数,先乘以100 System.out.println("第一次随机:"+Math.random()); System.out.println("第二次随机:"+Math.random()); Random r=new Random(); //随机数种子 //伪随机数 //根据种子计算出来的 //由种子决定随机数的产生序列 //默认时间做种子,没刷新一次,随机数更新一次 //r=new Random(10);//每次产生的随机数一样 System.out.println("范围内的随机数:"); for(int j=0;j<1;j++) { System.out.println(r.nextInt(10)); }
View Code
相关文章推荐
- Atitit. Atiposter 发帖机 新特性 poster new feature v7 q39
- leetcode 63. Unique Paths II | Java最短代码实现
- Atitit. Atiposter 发帖机 新特性 poster new feature v7 q39
- p235习题3
- DOM children childNodes nodetype
- 单一入口机制
- 1008_第几天
- Byte、bit、bps、Bps详解
- C++中的指针和动态分配二维数组问题
- GitHub关键词
- leetcode Merge k Sorted Lists
- Activity活动(下)
- 突然U盘不可以在32位centos 6.5 挂在了
- 【kAri OJ】621. 廖神的树
- 实验0 了解和熟悉操作系统
- make clean-kernel && make kernel
- Atitit.编程语言and 自然语言的比较and 编程语言未来的发展
- js中的匿名函数
- js中的this
- sorted的学习记录