zoukankan      html  css  js  c++  java
  • 课堂所讲整理:包装&工具类

     1 package org.hanqi.array;
     2 
     3 import java.util.Random;
     4 
     5 public class BaoZhuang {
     6 
     7     public static void main(String[] args) {
     8         
     9         //包装类
    10         Long l = new Long(100);
    11         //把字符串转成数值
    12         Long l1 = new Long("1000");        
    13         String str = 1000 + "";
    14         //从包装类转成基本数据类型
    15         long l2 = l1.longValue();
    16         System.out.println("l2="+l2);
    17         
    18         long l3 = Long.parseLong("1200");
    19         System.out.println(l3);
    20         
    21         //int
    22         Integer i = new Integer("100");
    23         Integer.parseInt("100");
    24         
    25         //float
    26         Float f = new Float("123.45");
    27         Float.parseFloat("123.45");
    28         
    29         //double
    30         Double d = new Double("12345.67");
    31         Double.parseDouble("123.78");
    32         
    33         //boolean
    34         Boolean b = new Boolean("ture");
    35         System.out.println(b.booleanValue());
    36         
    37         //数学工具类
    38         System.out.println(Math.PI);
    39         //四舍五入
    40         System.out.println(Math.round(1234.46789));
    41         double de = 1234.5678;
    42         System.out.println(Math.round(de));
    43         //保留小数点后2位
    44         System.out.println(Math.round(de*100)/100.0);
    45         //舍去小数点后的数字
    46         //下限值:小于或等于它的最大整数
    47         System.out.println(Math.floor(de));
    48         //上限值:大于或等于它的最小整数
    49         double de1 = 1234.06;
    50         System.out.println(Math.ceil(de1));
    51         //随机数 0-1 之间
    52         System.out.println(Math.random());
    53         System.out.println(Math.random());
    54         System.out.println(Math.random());
    55         System.out.println(Math.random());
    56         
    57         System.out.println();
    58         
    59         Random r = new Random();
    60         //随机数种子
    61         //伪随机数
    62         //根据种子计算
    63         //r = new Random(1);
    64         //默认使用时间做种子
    65         for(int m=0;m<10;m++)
    66         {
    67             System.out.println(r.nextInt(100));//限定范围的随机
    68         }
    69     }
    70 }

    运行结果为:

    相关思维导图:

  • 相关阅读:
    工作的思考十七:工作中容易犯的错误
    学习之路三十四:再一次重构缓存设计
    学习之路三十五:Android和WCF通信
    学习之路二十:两周工作技术总结
    学习之路三十三:重构技巧的学习
    工作的思考十五:升职前需要做的准备(TeamLeader)
    学习之路三十二:VS调试的简单技巧
    maven pom
    maven环境配置
    maven的背景
  • 原文地址:https://www.cnblogs.com/hanazawalove/p/5266680.html
Copyright © 2011-2022 走看看