This program is intended to match a string to another string and calculate the number common substrings they share. For some reason, it always prints the same incorrect values. Using the same methods, how can I make this code work as I intended it to?
public static void main(String[] args) {
String secret = "word";
String guess = "gzek";
int count = 0;
int length = secret.length();
int guess_length = guess.length();
for(int i=0;i<length-1;i++){
if(secret.substring(i, i).equals(guess.substring(i, i))){
count ++;
}
}
System.out.println(count);
}