I'm having trouble figuring out if a smaller string is a substring of a larger string. Example: s1 = boat s2 = steamboat Here is my code. I can only use for loops and charAt.
public static boolean isSubstring(String s1, String s2){
boolean substringcheck = false;
int correct = 0;
for(int i=0; i<s1.length(); i++){
for(int j=0; j<s2.length(); j++){
if(s1.charAt(i) == s2.charAt(j)){
correct++;
for(int n=0; n<s1.length(); n++){
if(s1.charAt(n) == s2.charAt(j)){
correct++;
}else{
correct = 0;
}
}
}
}
}
if(correct == s1.length()){
substringcheck = true;
}else{
substringcheck = false;
}
return substringcheck;
}
}
I'm confused on what to put after the if statement to check if all characters in the smaller string match with the ones after we find a match in the larger string.