Generate Random Numbers | Java Programs

Output:

Random Numbers:
***************
47
60
18
9
67
----------------
Random Numbers:
***************
78
68
14
79
69

Click Here For Java Online Compiler

Solution:

import java.util.*;
class GenerateRandomNumbers {
   public static void main(String[] args) {
      Random r = new Random();
      int howManyRandom = 5;
      System.out.println("Random Numbers:");
      System.out.println("***************");
      for (int i = 1; i <= howManyRandom; i++) {
         System.out.println(r.nextInt(100)); //Here 100 shows that random number
      }                                  //will not exceed 100
   }
}
Share This :

Related Post



sentiment_satisfied Emoticon