WAP to get a age from user ,, if user age less then 18 ,, throw an exception and print you are not elligible for vote access denied ,if age is 18 or greater and print you are elligible for vote access granted.
PROGRAM CODE--
import java.util.Scanner;
import java.io.*;
class Age
{
int m;
public void get(int n) throws Exception
{
m=n;
if(m<18)
{
throw new ArithmeticException(" you are not elligible for vote !!!!!access is denied");
}
else
{
System.out.println(" you are elligible for vote !!!access granted");
}
}
}
class CallAge
{
public static void main(String ar[])
{
int a;
System.out.println("enter ur age");
try
{
Scanner s= new Scanner(System.in);
a=s.nextInt();
Age ob = new Age();
ob.get(a);
}catch(Exception e)
{
System.out.println(e);
}
}
}



Comments
Post a Comment