Files
javaSE260715-new/day07/src/com/inmind/random02/Demo05.java
T

18 lines
566 B
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}