Random Number Generator Program in Java

 import java.util.*;  
 class random   
 {  
      public static int x=10;  
      public static void main(String[] args)   
      {  
           Random rand = new Random();  
           for (int i=0;i<5 ;i++ )  
           {  
                int num = rand.nextInt(6);  
           System.out.println("Generated Random Number between 0 to 6 is : " + num);  
           }  
           random obj=new random();  
           System.out.println("Generated Random Number "+random.x);  
           int numNoRange = rand.nextInt();  
           System.out.println("Generated Random Number "+  
           "without specifying any range is : " + numNoRange);  
      }  
 }  

Post a Comment

0 Comments