Solution:
There is a built-in class in java name java.util.Random. The nextFloat() is a method of that class. It generates a random float between 0.0 (inclusive) to 1.0 (exclusive). Let’s use the class and its method to generates random float number in a java program
import java.util.Random;
public class MyClass {
public static void main(String[] args) {
Random obj = new Random();
System.out.println(obj.nextFloat());
}
}
The output I got
0.9972967