zoukankan      html  css  js  c++  java
  • 包装&工具类

    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
            long l3=Long.parseLong("1200");
            
            
            //int 
            Integer i=new Integer("100");
            
            //静态方法  从字符串转成int
            Integer.parseInt("100");
            
            
            //float
            Float f=new Float("123.45");
            
            Float.parseFloat("1234.56");
            
            
            //double
            Double d=new Double("12345.67");
            
            Double.parseDouble("123.78");
            
            
            //boolean
            Boolean b=new Boolean("true");
            
            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*100)/100.00);
            
            //舍去小数点后的数字
            
            //下限值:小于或等于它的最大整数
            System.out.println(Math.floor(de));
            
            //上限值:大于或等于它的最小整数
            System.out.println(Math.ceil(de));
            
            
            //随机数 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(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));
            }
            
            
            //摇奖程序
            
            //产生验证码
            
            
            
    
        }
    
    }

  • 相关阅读:
    12-认识容量和升(四上)
    11 认识1-5(一上)
    10 圆柱的表面积(六下)
    009 单式折线统计图(五下)
    008 解决问题的策略 转化(苏教版 五下)
    007 分数的基本性质(五下)
    006 三位数乘两位数(四上)
    kafka,MQ消息队列
    005 圆的周长(六上)
    004 平行四边形的面积(五上)
  • 原文地址:https://www.cnblogs.com/cycanfly/p/5267380.html
Copyright © 2011-2022 走看看