logo image

Java program to take a max limit from user and generate a random number till that number



Following program shows you how to take a max limit from user and generate a random number till that number. In this program we get max limit number from user and generate a random number using Random rnum = new Random()

import java.util.Random;
import java.util.Scanner;

public class Basic10 {

	public static void main(String[] args) {

		System.out.println("Enter maxlimit to generate a random number:");

		int counter;
		Random rnum = new Random();

		Scanner in = new Scanner(System.in);
		int maxLimit = in.nextInt();

		int result = rnum.nextInt(maxLimit);

		System.out.println("Random number is: " + result);
	}
}

Output:

Enter maxlimit to generate a random number:
200
Random number is: 65