How do I find out how many digits a String has in Java? For example, user entered with "example123", the string has 3 digits. I am using this function but it is not working:
private static int digitos(String text) {
char[] digitos = new char[9];
int digitosTotal = 0;
for (int i = 0; i != 9; i++) {
digitos[i] = (char) i;
}
for (int i = 0; i < digitos.length; i++) {
if (text.indexOf(digitos[i]) != -1) {
digitosTotal++;
}
}
return digitosTotal;
}