KnowledgeBoat Logo

Computer Applications

Write a program to generate random integers in the following ranges:

i. 10 to 20 (both inclusive)
ii. 25 to 50 (both inclusive)

Java

Java Math Lib Methods

ICSE

6 Likes

Answer

public class KboatRandom
{
    public static void main(String args[]) {
        int min = 10, max = 20;
        int range = max - min + 1;
        int num = (int)(range * Math.random() + min);
        System.out.println("Random number in the range 10 to 20: " + num);
        
        min = 25;
        max = 50;
        range = max - min + 1;
        num = (int)(range * Math.random() + min);
        System.out.println("Random number in the range 25 to 50: " + num);
    }
}

Output

BlueJ output of Write a program to generate random integers in the following ranges: i. 10 to 20 (both inclusive) ii. 25 to 50 (both inclusive)

Answered By

5 Likes


Related Questions