zoukankan      html  css  js  c++  java
  • java的随机数Random

    测试1

     1 package com.lv.study.pm.second;
     2 
     3 public class TestMath {
     4 
     5     public static void main(String[] args) {
     6 
     7         //随机得到一个浮点数Math.random()
     8         System.out.println(Math.random()*100/10);
     9         
    10         int it=(int) (Math.random()*1000/10);
    11         System.out.println(it);
    12         
    13         
    14     }
    15 
    16 }

    测试2

     1 package com.lv.study.pm.second;
     2 
     3 import java.util.Random;
     4 
     5 public class TestRandom {
     6 
     7     public static void main(String[] args) {
     8 
     9         Random rd=new Random();
    10         
    11         //随机得到int类型范围的 一个随机数
    12         System.out.println(rd.nextInt());
    13         
    14         //随机得到0-9的数
    15         System.out.println(rd.nextInt(10));
    16         
    17         //随机得到一个布尔值
    18         if(rd.nextBoolean()){
    19             System.out.println("今天赢钱了 大");
    20         }else{
    21             System.out.println("今天输了 小");
    22         }
    23         
    24         
    25     }
    26 
    27 }
  • 相关阅读:
    指针、字符串、数组操作
    字符串转换为数字(str2int)
    新的,开始。
    Hello, World.
    Go语言趣学指南lesson1
    hdoj2058
    poj2378
    hdoj1233
    poj2398
    hdoj1392
  • 原文地址:https://www.cnblogs.com/dabu/p/12412002.html
Copyright © 2011-2022 走看看