SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Solution checker is broken
  2.  
  3. /**
  4.    Counts the number of times a character appears in a string.
  5. */
  6.  
  7. public class CharCounter
  8. {
  9.    /**
  10.       Returns the number of times that a target character
  11.       appears in a string.
  12.       @param source the input string
  13.       @param ch the character to be counted (a string of length 1)
  14.       @return the number of times the target character
  15.       appears in the source
  16.    */
  17.    public static int countChar(String str, char c)
  18.    {
  19.       int count = 0;
  20.       for(int i = 0; i < str.length(); i++)
  21.       {
  22.          if(str.charAt(i) == c){count++;}
  23.       }
  24.       return count;
  25.    }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top