Pages

Saturday, March 21, 2015

Write a Program to Generate Random Number

Input:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
/*
 * Write a Program to generate random number
 */
package random12;

import java.util.Random;
public class Random12 {

    public static void main(String[] args) {
        // TODO code application logic here
           Random rnd = new Random();
        for (int j = 0; j < 5; j++) {
            System.out.printf("%2d \t", rnd.nextInt() );
        }// end of for loop
    }// end of main
}// end of class

Output:


-1603606673  439348859  -1927187981  -245239965  -1529655924 

No comments:

Post a Comment