Write a Java program to validate the full name of an employee using exception

import java.util.*;
class InvalidNameException extends Exception
{
}
class Emp
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the Employee Name ");
String name=s.next();
try
{
for(int i=0;i {
int ch=(int)name.charAt(i);
if((ch>=65&&ch<=90)||(ch>=97&&ch<=122))
{
}
else
{
throw new InvalidNameException();
}
}
System.out.println("Employee Name is :"+name);
}
catch(InvalidNameException e)
{
System.out.println("Invalid Employee Name ");
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *