0

[Java] Any class or method returning a random number?

What class to import? What's the method and its usage?

8th Feb 2017, 1:19 AM
Martín Lehoczky
Martín Lehoczky - avatar
3 Respuestas
+ 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);     } }
8th Feb 2017, 5:34 AM
Vânia Almeida
Vânia Almeida - avatar
+ 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);    } }
8th Feb 2017, 5:37 AM
Vânia Almeida
Vânia Almeida - avatar