18 lines
566 B
Java
18 lines
566 B
Java
package com.inmind.random02;
|
||
|
||
import java.util.Random;
|
||
|
||
public class Demo05 {
|
||
public static void main(String[] args) {
|
||
//1.创建Random对象
|
||
Random random = new Random();
|
||
//2.获取随机值
|
||
for (int i = 0; i < 20; i++) {
|
||
// int v = random.nextInt();//获取int取值范围的随机数,太大了
|
||
// int v = random.nextInt(10);//(java中是包头不包尾)获取0~9
|
||
int v = random.nextInt(3,8);//(java中是包头不包尾)获取3~7
|
||
System.out.println(v);
|
||
}
|
||
}
|
||
}
|