0

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;
  }
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by apegram
0

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

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.