Fri Sep 10 2021

Random Number

File Name: random-number.java

import java.io.*;
import java.util.Random;

class random_number {
	public static void main(String args[ ]) {
		int no;

		/* Create object of Random class */
		Random rn = new Random();

		/* Generate random number from 1 to 10 */
		no = rn.nextInt(10) + 1;
		System.out.println("Random Number: "+no);
	}
}



/* Output */
Random Number: 4

/* ------------------------- */

Random Number: 6
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.