Advertisements
Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!
Hi Friend,
Try the following code:
import java.util.*; public final class RandomNumberBetweenTwoIntegers { public static final void main(String[] args){ int min = 115; int max = 250; Random random = new Random(); long range = (long)max - (long)min + 1; long fraction = (long)(range * random.nextDouble()); int randomNumber = (int)(fraction + min); System.out.println(randomNumber); } }
Thanks