Generate Random Integer in Range using Java

Random.nextInt method

package app;

import java.util.Random;

public class Main
{
    public static void main(String[] args)
    {
        int minValue = 1;
        int maxValue = 100;
        int randValue = new Random().nextInt((maxValue - minValue) + 1) + minValue;

        System.out.println(randValue);
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.