Java – How to create a random number which is less than 25 ?

Problem Statement

You need to create a random number which is less than 25 in Java.

Solution

Use the Random class’s nextInt method and pass the value within which the random number needs to be generated.

import java.util.Random;

public class Main {

    public static void main(String[] args) {
        Random rand1 = new Random();
        int output = rand1.nextInt(25);
        System.out.println(output);
    }
}