-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomNumberGenerator.java
More file actions
23 lines (22 loc) · 1.01 KB
/
RandomNumberGenerator.java
File metadata and controls
23 lines (22 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Random;
import java.util.Scanner;
public class RandomNumberGenerator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
System.out.println("Enter the lower limit:");
int lowerLimit = scanner.nextInt();
System.out.println("Enter the upper limit:");
int upperLimit = scanner.nextInt();
int randomNumber = random.nextInt(upperLimit - lowerLimit + 1) + lowerLimit;
System.out.println("Generated random number:" + randomNumber);
if (randomNumber < lowerLimit + (upperLimit - lowerLimit) / 3) {
System.out.println("The number is in the lower third of the range.");
} else if (randomNumber < lowerLimit + 2 * (upperLimit - lowerLimit) / 3) {
System.out.println("The number is in the middle third of the range.");
} else {
System.out.println("The number is in the upper third of the range.");
}
scanner.close();
}
}