0
[Java] Any class or method returning a random number?
What class to import? What's the method and its usage?
2 Respostas
+ 3
import java.util.Random;
public class RandomNumber {
public static void main(String[] args) {
Random generator = new Random();
int number = generator.nextInt();
System.out.println(number);
}
}
+ 3
Example, if you want a number between 0 and 9.
import java.util.Random;
public class Random {
public static void main(String[] args) {
Random generator = new Random();
int number = generator.nextInt(10);
System.out.println(number);
}
}