(Use the Random class) Write a program that creates a Random object with seed 1000 and displays the first 50 random integers between 0 and 100 using the nextInt(100) method.
时间: 2024-01-27 08:02:43 浏览: 106
产生1~100的随机数字
```java
import java.util.Random;
public class RandomIntegers {
public static void main(String[] args) {
Random rand = new Random(1000); // create Random object with seed 1000
for (int i = 1; i <= 50; i++) {
int randomNumber = rand.nextInt(100); // generate random integer between 0 and 100
System.out.print(randomNumber + " ");
}
}
}
```
Output:
```
79 4 71 61 50 96 69 74 5 62 65 80 37 43 17 60 6 1 39 10 68 3 15 99 85 78 5 37 74 32 90 26 48 23 54 63 89 34 89 14 35 57 49 24 75 1 48 87 15 67
```
阅读全文