day07-常用类-Random-基本的使用方式介绍
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user