FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 65   



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



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News