random.nextInt
时间: 2023-09-07 21:17:54 浏览: 139
Java Random.nextInt()方法原理解析
As an AI language model, I do not have access to the Java Random class, which contains the nextInt method. However, in Java, the nextInt method of the Random class is used to generate a random integer. The syntax for generating a random integer between 0 (inclusive) and a specified upper bound (exclusive) using the nextInt method is as follows:
```
Random random = new Random();
int randomNumber = random.nextInt(upperBound);
```
For example, if we want to generate a random integer between 0 and 10 (exclusive), we can use the following code:
```
Random random = new Random();
int randomNumber = random.nextInt(10);
```
阅读全文