I need help with my class assignment. I am supposed to write a java program to count the number of digits in a string using: public static int countDigits(String s)
can anyone help...I cant seem to figure it out from what I have
public class Ex8_5 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();
System.out.println("The number of digits is " + countDigit(s));
}
public static int countDigits(String s) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (Character.isLetter(s.charAt(i))) {
count++;
}
}
return count;
}
}