June 2018
Beginner
722 pages
18h 47m
English
The method doubles() of the class Random generates a double type value greater than or equal to 0.0 and less than 1.0:
Random random = new Random();for(int i =0; i < 3; i++){ System.out.print(random.nextDouble() + " "); //prints: 0.8774928230544553 0.7822070124559267 0.09401796000707807 }
We can use the method nextDouble() the same way we used Math.random() in the previous section. But class have other methods that can be used without creating a custom getInteger() method when a random integer value of a certain range is required. For example, the nextInt() method returns an integer value between Integer.MIN_VALUE (inclusive) and Integer.MAX_VALUE (inclusive):
for(int i =0; i < 3; i++){ System.out.print(random.nextInt() ...
Read now
Unlock full access