package com.itheima;
import java.util.Random;
/*
Random的基本使用
*/
public class Scanner03 {
public static void main(String[] args) {
//Random():创建一个新的随机数生成器
Random r=new Random();
// //int nextInt(int bound);获取一个Int类型的随机数,参数bound表示,获取到的随机数在[0,bound)之间
//// int i = r.nextInt(20);
//// System.out.println(i);
// for (int i=1;i<=10;i++) {
// int j = r.nextInt(10);
// System.out.println(j);
// }
//如何获取1-100之间的随机数呢?
// int number = r.nextInt(101);//0-100
int number = r.nextInt(100)+1;//0-100
System.out.println(number);
}
}
执行结果
91
Process finished with exit code 0
标签:JAVA,int,Random,bound,nextInt,随机,随机数,public
From: https://www.cnblogs.com/cy-xt/p/16839279.html