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 Random_Numbers {

public static void main(String[] args) {

int a;
int range;
int random_Number;
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++)
random_Number = rd.nextInt(100);
System.out.print(random_Number + " ");


Random Numbers In Java

Sharing is healthy !!

Leave a Reply

Your email address will not be published.