• 包装&工具类


    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));
            }
            
            
            //摇奖程序
            
            //产生验证码
            
            
            
    
        }
    
    }

  • 相关阅读:
    二分查找经典题型
    部队侦察
    取随机数函数的使用
    猜拳游戏
    Learning C Struct
    Linux shell get random number
    Linux Bash shell one practice : array if else
    Linux shell misc
    Bash Shell read file line by line and substring
    storm的并发和消息保障性
  • 原文地址:https://www.cnblogs.com/cycanfly/p/5267380.html
Copyright © 2020-2023  润新知