posted 19 years ago
Maha:
Since you are a beginner, I thought it would be useful to show a simple way to see if a string contains a digit. Although there are more efficient methods of accomplishing this task, the following code is easy to understand and will give you a starting point.
This approach simply examines each character in a string by using the charAt method of String. It then tests that character by using the isDigit method of Character. If a digit is found, the loop stop early. If a loop completes, it means that no digit was found. The output is shown here.
str has no digits
str2 has digits
This will get you started, but I am sure that you can do better.
For my latest books on Java, including Introducing JavaFX 8 Programming, see HerbSchildt.com