private int countOccurrences ( String haystack , char needle ) { int count = 0 ; for ( int i = 0 ; i < haystack . length ( ) ; i ++ ) { if ( haystack . charAt ( i ) == needle ) count ++ ; } return count ; }
Count how many time needle appears in haystack