Answer:
//import Random package
import java.util.Random;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
try{
/* create an object of Random class. this will generate random number
in a given range. */
Random rand = new Random();
// create two variables and assign 100 and 250 to
int l = 100;
int h = 250;
//generate the random number between 100 & 250 (inclusive)
int ran_num = rand.nextInt((h+1)-l) + l;
System.out.println("random number is: "+ran_num);
}catch(Exception ex){
return;}
}
}
Step-by-step explanation:
Import "import java.util.Random" package.In this package, Random class exist. With the help of this class's object, we can generate a random number between a given range.Here we have to generate a random number between 100 to 250(inclusive). So "(h+1)-l" will be 151 and the number generate is in the range of 0-150. if we add 100 to it, then random number will be in range of 100 to 250.
Output:
random number is: 158