Skip to content

Instantly share code, notes, and snippets.

@thiagofm
Created May 2, 2011 04:03
Show Gist options
  • Select an option

  • Save thiagofm/951170 to your computer and use it in GitHub Desktop.

Select an option

Save thiagofm/951170 to your computer and use it in GitHub Desktop.
public class ProcuraOcorrencia {
public static void main(String[] args){
String s1 = "carrocaacaca";
String s2 = "ca";
int ocorrencias = 0;
for(int i=0;i<s1.length();i++){
if(s1.charAt(i)==s2.charAt(0)){
for(int j=0; j<s2.length();j++){
if(s1.charAt(i)!=s2.charAt(j)){
break;
}
if(j==s2.length()-1){
ocorrencias++;
} else {
i++;
}
}
}
}
System.out.println(ocorrencias);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment