/* related posts with thumb nails */

An interactive program to accept name of a person and validate it. If the name contains any numeric value throw an exception “InvalidName”.:

import java.io.*;

class InvalidName extends Exception

{

public void showError()

{

System.out.println("Error:Name contains digits");

}

}

class NameTest

{

public static void main(String as[]) throws Exception

{

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(isr);

String name;

int i;

try

{

System.out.println("Enter Name:");

name=br.readLine();

for(i=0;i

{

char ch=name.charAt(i);

if(Character.isDigit(ch))

throw new InvalidName();

}

System.out.println("Your Name:"+name);

}

catch(InvalidName e)

{

e.showError();

}

}

}

/* Output: */

Enter Name:Ravi12

Error:Name contains digits

Related Topics:

0 comments:

Post a Comment