-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample5.java
More file actions
24 lines (20 loc) · 742 Bytes
/
Copy pathExample5.java
File metadata and controls
24 lines (20 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class Example5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the speed Limit in km/hrs: ");
int limit = sc.nextInt();
try {
// Check the speed limit
if (limit >= 120) {
// Throw an exception if the speed limit is exceeded
throw new IllegalArgumentException("Speed limit exceeded! Please drive safely.");
} else {
System.out.println("No issue with the speed.");
}
} catch (IllegalArgumentException e) {
// Handle the exception
System.out.println(e.getMessage());
}
}
}