Advertisement
advictoriam

Untitled

Jan 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement