day07-random类的使用与练习
This commit is contained in:
18
day07/src/com/inmind/random02/Demo06.java
Normal file
18
day07/src/com/inmind/random02/Demo06.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.inmind.random02;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/*
|
||||
获取10个55~66之间的值,(包含55和66)
|
||||
|
||||
random.nextInt(10);//获取0~9的随机数
|
||||
*/
|
||||
public class Demo06 {
|
||||
public static void main(String[] args) {
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
int result = random.nextInt(12)+55;//0~9: 55~66 -55 -->0~11--->12
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user