Count the number of ' a ' , ' b ' and ' c ' in string
int ca = 0 , cb = 0 , cc = 0 ; StringBuilder s = new StringBuilder ( str ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( s [ j ] == ' a ' ) ca ++ ; else if ( s [ j ] == ' b ' ) cb ++ ; else cc ++ ; }