Search This Blog

Wednesday 13 August 2014

Generate Random Number - JAVA

import java.util.Random;

/**
 * How to generate Random numbers in Java
 *
 */
public class MainClass {
public static void main(String[] args){
Random random = new Random();
int randomNo = random.nextInt();
System.out.println("Random number is: " + randomNo);

int randomNo2 = random.nextInt(5);
System.out.println("Random number generated between 0 and 4 is: " + randomNo2);
}
}

No comments:

Post a Comment