/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package examples;
import java.util.Scanner;
/**
*
* @author lakmal
*/
public class Name {
String name;
void getName() {
Scanner input = new Scanner(System.in);
System.out.println("Enter Your name:");
name = input.next();
this.checkName();
}
void checkName() {
boolean isValid = true;
for (int i = 0; i < name.length(); i++) {
if (Character.isDigit(name.charAt(i))) {
isValid = false;
continue;
}
}
if (isValid) {
System.out.println("Your name is " + name);
} else {
System.out.println("Name should not have any Integers");
this.getName();
}
}
public static void main(String[] args) {
Name name1 = new Name();
name1.getName();
}
}
check this out !! Hope you will understand the code !!!