day07--常用类-Random-基本的使用方式介绍
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.inmind.random02;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/*
|
||||
随机数
|
||||
*/
|
||||
public class Demo03 {
|
||||
public static void main(String[] args) {
|
||||
//创建随机类对象
|
||||
Random random = new Random();
|
||||
//调用对象的方法
|
||||
for (int i = 0; i < 10; i++) {
|
||||
//3~13 -3 ->0~10
|
||||
//int value = random.nextInt(11)+3;//取值范围为0~9,在java中包头不包尾
|
||||
int value = random.nextInt(3,14);//取值范围为0~9,在java中包头不包尾
|
||||
System.out.println(value);
|
||||
}
|
||||
|
||||
System.out.println("程序结束");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user