Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class VoterException
- {
- public static void main(String args[])
- {
- Scanner s = new Scanner(System.in);
- System.out.print("Enter Age : ");
- int age = s.nextInt();
- check(age);
- }
- static void check(int a)
- {
- try
- {
- if(a<18)
- {
- throw new MyException(a);
- }
- else
- {
- System.out.println("Your age is eligible for voting");
- }
- }
- catch(MyException e)
- {
- System.out.println(e);
- }
- }
- }
- class MyException extends Exception
- {
- int num;
- MyException(int a)
- {
- num = a;
- }
- public String toString()
- {
- String s = "Your age is not eligible for voting";
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment