以下是常用的各两种方法(各类提供了构造方法,静态方法)

一、基本数据类型 转化为 包装类(装箱

  例:int i=10;

    Integer num=i;//num=10

二、包装类 转化为  基本数据类型 (拆箱

  例:Integer num=10;

    int i=num;//i=10


三、基本数据类型  转化为 String类

  例:int i=10;

    String str=i+'' '';//  "10"

四、String类  转化为  基本数据类型

  例:String str="123";

    int i=Integer.parseInt(str);//123


五、包装类  转化为 String类

  例:Integer num=123;

    String str=num+"";//"123"

六、String类  转化为  包装类

  例:String str="123";

  Integer num=Integer.parseInt(str);//123


  随机数

一、Math

    公式为 (int)(Math.Random()*(Max-Min+1)+Min)

二、Random

    公式为 (int)(Random.nextInt(Max-Min+1)+Min)

例:  使用Math类随机产生100个2~99的的整数(包括2,包括99)

// 使用Math.random()产生随机数
  for (int i = 0; i < 100; i++) {
  System.out.print((int) (Math.random() * (99 - 2 + 1) + 2) + ",");   if (i != 0 && i % 10 == 0) {
    System.out.println();
  }
} // 使用Random类产生随机数
  Random r = new Random();
  System.out.println(r.nextInt());   Random r1 = new Random(1000);// 提供种子
  System.out.println(r1.nextInt());
  Random r2 = new Random(1000);// 结果相同
  System.out.println(r2.nextInt());   System.out.println();   for (int i = 0; i < 100; i++) {
  System.out.print((int) (r2.nextInt(99 - 2 + 1)+ 2)+",");
  if (i != 0 && i % 10 == 0) {
  System.out.println();
  }
}

最新文章

  1. 《与小卡特一起学Python》Code3 抓取网页中的某个数据
  2. Windows Server 2012 没有远程桌面授权服务器可以提供许可证,远程会话被中断
  3. 不同场景下 MySQL 的迁移方案
  4. HoloLens开发手记 - 应用程序模型 App model
  5. 【转】【C#】【Thread】Mutex 互斥锁
  6. JVM的GC理论详解
  7. VS插件开发
  8. c++ 实现百度自动搜索
  9. 8.css边框
  10. 01-08-02【Nhibernate (版本3.3.1.4000) 出入江湖】二级缓存:NHibernate自带的HashtableProvider
  11. eventlet的学习
  12. hdu_5794_A Simple Chess(lucas+dp)
  13. Web Worker 初探
  14. Python从入门到精通之First!
  15. SQL调优日记--并行等待的原理和问题排查
  16. python之全局安装包管理工具pip
  17. day 26
  18. Rsync 软件的工作方式
  19. SSH框架整合的其它方式
  20. python之ftp作业【还未完成】

热门文章

  1. 使用node打造自己的命令行
  2. Windows安装python包出现PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问的问题解决方案
  3. uWSGI, send_file and Python 3.5
  4. 深度学习与人类语言处理-语音识别(part1)
  5. C语言程序设计(十二) 结构体和共用体
  6. JsonFormat 日期少了8个小时?还我
  7. python3使用js2py
  8. 解决QQ“抱歉,无法发起临时会话,您可以 添加对方为好友以发送消息”
  9. 利用JDBC工具类添加和查询数据-Java(新手)
  10. 手把手教大家如何用scrapy爬虫框架爬取王者荣耀官网英雄资料