Java Program to generate Random Numbers

This Java program is to generate random numbers, in below program source code we have generated 5 random numbers using Math.random method  between 1 to 100. Yo can change the number of random numbers from 5 to any times by editing for loop in the below code.

Java Program to generate Random Numbers

 /*Write a program to generate 5 Random numbers between 1 to 100, and it  should not follow with decimal point.
Program by Codext.com
*/

class Random{

      public static void main(String args[]){

          for(int i=1;i<=5;i++){

              System.out.println((int)(Math.random()*100));

          }

    }

}

Output of Java Program to generate Random Numbers

The above screenshot shows how the random numbers are generated in Java, here 5 random numbers are generated each time whenever we have executed this java program generating different values.

0 comments:

Post a Comment