random.nextint
时间: 2024-01-03 10:03:21 浏览: 82
As an AI language model, I do not have access to a specific context or programming language. However, "random.nextInt" is a method used in Java to generate a random integer value within a specified range. It is part of the "java.util.Random" class and can be used as follows:
Syntax: random.nextInt(n)
- "random" is an instance of the "Random" class.
- "n" is the upper bound of the range (exclusive).
- The method returns a random integer between 0 (inclusive) and n (exclusive).
Example:
import java.util.Random;
public class RandomExample {
public static void main(String[] args) {
Random random = new Random();
int randomNumber = random.nextInt(10);
System.out.println("Random number: " + randomNumber);
}
}
Output:
Random number: 7 (this value will vary every time the program is executed)
阅读全文