import java.util.*;
public class AgeException
{
public static void main (String [] args)
{
Scanner s = new Scanner(System.in);
while(true)
{
try
{
System.out.println("Enter ur Age");
int n=s.nextInt();
int x=age(n);
return;
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
public static int age(int n)throws Exception
{
if (n<18 || n>60)
throw new Exception ("Please Enter age18 to 60");
System.out.println("You r selected");
return n;
}
}
public class AgeException
{
public static void main (String [] args)
{
Scanner s = new Scanner(System.in);
while(true)
{
try
{
System.out.println("Enter ur Age");
int n=s.nextInt();
int x=age(n);
return;
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
public static int age(int n)throws Exception
{
if (n<18 || n>60)
throw new Exception ("Please Enter age18 to 60");
System.out.println("You r selected");
return n;
}
}
No comments:
Post a Comment
Thank You !