Home >Java >Javagetting Started >How to generate random numbers between 1 and 100 in java
You can use the random() method, which is used to return a random number. The range of the random number is 0.0 =< Math.random < 1.0.
Note: This is a default method and does not accept any parameters.
(Recommended video tutorial: java video)
Example:
int i = (int)(Math.random()*100+1);
Recommended tutorial: java entry program
The above is the detailed content of How to generate random numbers between 1 and 100 in java. For more information, please follow other related articles on the PHP Chinese website!