-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomNumberGenerator.java
More file actions
45 lines (33 loc) · 1.4 KB
/
RandomNumberGenerator.java
File metadata and controls
45 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Random;
import java.util.Scanner;
public class RandomNumberGenerator {
public static void main(String[] args) {
try (Scanner scan = new Scanner(System.in)){
Random random = new Random();
System.out.print("Enter the lower limit: ");
int lowerLimit = scan.nextInt();
System.out.print("Enter the upper limit: ");
int upperLimit = scan.nextInt();
int randomNumber = random.nextInt(upperLimit-lowerLimit+1) + lowerLimit;
System.out.println("Generated random number is " + randomNumber);
if(randomNumber < 0) {
System.out.println("The number is below Zero");
}
else if (randomNumber> 0 && randomNumber <= 10) {
System.out.println("The number is between 0 and 10");
}
else if (randomNumber> 10 && randomNumber <= 20) {
System.out.println("The number is between 10 and 20");
}
else if (randomNumber> 20 && randomNumber <= 50) {
System.out.println("The number is between 20 and 50");
}
else {
System.out.println("The number is above 50");
}
}
catch (Exception e) {
System.err.println("Please enter Number only!");
}
}
}