Start New Discussion within our Software Development Community

I am developing a code to find the occurence of digits in a string. I need help. When it compiles I get the error: cannot find symbol variable countDigits

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 " + countDigits());
  }
  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;
  }
}

For one, your countDigits method is expecting a string parameter, yet you are calling it without one.