Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Solution checker is broken
- /**
- Counts the number of times a character appears in a string.
- */
- public class CharCounter
- {
- /**
- Returns the number of times that a target character
- appears in a string.
- @param source the input string
- @param ch the character to be counted (a string of length 1)
- @return the number of times the target character
- appears in the source
- */
- public static int countChar(String str, char c)
- {
- int count = 0;
- for(int i = 0; i < str.length(); i++)
- {
- if(str.charAt(i) == c){count++;}
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement