954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

find occurence of digits in a string

0
By akonful on Feb 3rd, 2010 11:23 am

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.

apegram
LINQ!
Team Colleague
552 posts since Jan 2010
Reputation Points: 327
Solved Threads: 135
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You