0
how to force the user to enter only strings in java
2 Réponses
+ 1
Question is not clear...
+ 1
You can take this as a solution but you can't force a user to enter only string on a console :
System.out.println("Enter your name: ");
String name = in.nextLine();
while(!name.matches("[a-zA-Z]+")){
System.out.println("Please enter a valid name!");
name = in.nextLine();
}