find occurence of digits in a string

akonful 0 Tallied Votes 186 Views Share

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;
  }
}
apegram 302 LINQ! Team Colleague

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.