This is a simple Java programs which will generate and print the random numbers with the help of inbuilt Java classes java.util.Random
. At the end of this program, I have shared some execution result for more understanding.
Copy the below Java programs and execute it with the help of Java compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//importing java.util.Random class; import java.util.Random; public class generateRandom{ public static void main(String args[]) { // create instance of Random class Random rand = new Random(); // Generate random integers in range 0 to 999 int rand_int1 = rand.nextInt(100000); int rand_int2 = rand.nextInt(100000); // Print random integers System.out.println("Random Integers: "+rand_int1); System.out.println("Random Integers: "+rand_int2); // Generate Random doubles double rand_dub1 = rand.nextDouble(); double rand_dub2 = rand.nextDouble(); } } |
Random Integers: 9568
Random Integers: 37280
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Java program, Java program to generate random number, Java programming, Java programs, Java programs with examples, Java programs with output, random number generator java, random number program, random number program in java