- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram27_Throw.java
More file actions
Latest commit
21 lines (18 loc) · 629 Bytes
/
Copy pathProgram27_Throw.java
File metadata and controls
21 lines (18 loc) · 629 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Write a java program using throw keyword to throw custom exception.
// Date : 20/03/2024, Author : Yash Wadhvani
importjava.util.Scanner;
publicclassProgram27_Throw {
staticvoidcheckAge(intage) {
if (age < 18) {
thrownewArithmeticException("You are not a Legal Adult, Access Denied");
}
System.out.println("You are a Legal Adult, Access Granted");
}
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
System.out.println("Enter your Age :");
intage = sc.nextInt();
sc.close();
checkAge(age);
}
}