Errors out of bounds saying,
java.lang.StringIndexOutOfBoundsException: String index out of range: 6 (in.java.lang.String)
when I run the code. I am trying to find how many identical characters two strings have in the same spots.
Public static void main(String[] args) {
System.out.println(countAlike("happy","damp");
}
public static int countAlike(String a, String b) {
int acount = a.length();
int bcount = b.length();
int countAlike = 0;
for(int i = 0; i <= bcount; i++){
for(int l = 0; l <= bcount; i++){
if(a.substring(i,i+1).equals(b.substring(l,l+1))){
countAlike += 1;
}
else{
}
}
}
return countAlike;
}