Oh, I thought this was for C not java. Sorry. jdwilder's solution would work too, but I believe it would be:
String s=new String("stsigijfgigdfksssdoggog");
int counter = 0; // better to be explicit
for (int i=0;i<s.length();i++){
if (s.charAt(i)=='s')counter++;
}
|