Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CountChar {
- public static int getChar(String str, char chr) {
- int count = 0, pos = 0;
- while (str.indexOf(chr, pos) != -1) {
- count++; pos++;
- }
- return count;
- }
- public static void main(String[] args) {
- System.out.println("a in aaaa: " + getChar("aaaa", 'a'));
- System.out.println("b in aaaa: " + getChar("aaaa", 'b'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement