Random Numbers In Java

Sharing is healthy !!

Hello everyone!!! Let me explain random numbers in java.

Well, there are many ways in java to generate random numbers.

In the following example we are going to demonstrate random numbers using for loop.

example: Random Numbers In Java

Also Read – Java Program To Find Prime Number

import java.util.Scanner;
import java.util.Random;

public class RandomNumbers
{
   public static void main(String[] args)
   {
      int a;
      int range;
      int randomNumber;
 
      Random rd = new Random();
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter random numbers you want to generate: ");
      range = sc.nextInt();
 
      // Generating random numbers between range 0 - 100
 
      for(a = 0;a <= range; a++)
      {
         randomNumber = rd.nextInt(100);
         System.out.print(randomNumber + " ");
      }
   }
}

Output:

Random Numbers In Java

Sharing is healthy !!