Monday, 2 November 2015

Generate Random numbers


Write a program to generate 5 random numbers between 1 to 100, and it should not follow with decimal point.

Input:- 5

Output:- Any 5 random numbers between 1 to 100.


Sample Program:-

 /**  
  * @author Dixit  
  *   
  */  
 public class GenerateRandomNumber {  
      /**  
       * @param args  
       */  
      public static void main(String[] args) {  
           for (int i = 1; i <= 5; i++) {  
                System.out.println((int) (Math.random() * 100));  
           }  
      }  
 }  

Output  
 11  
 76  
 27  
 84  
 90  

Enjoy Programming

No comments:

Post a Comment