0

how to force the user to enter only strings in java

1st Nov 2021, 5:19 PM
yvan Chrys
2 Réponses
+ 1
Question is not clear...
1st Nov 2021, 5:42 PM
Jayakrishna 🇮🇳
+ 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(); }
1st Nov 2021, 6:24 PM
Sangam Sharma
Sangam Sharma - avatar