Yes.
Now look at the parts 2 and 3 of the recursive definition:
and the Java code:
if ( strA.isEmpty() && strB.isEmpty() )
return true;
else if ( strA.isEmpty() || strB.isEmpty() )
return false;
...
Rules 2 and 3 say to return false if one string is empty but the other string is not.
This is what the Java code does.
The first if
returns true if both strings are empty.
So the else if
is executed only when at least one string has characters in it.
If the other string is empty, the strings are not equal (so return false).
Does this Java code:
else if ( strA.charAt(0) != strB.charAt(0) ) return false; else return myEquals( strA.substring(1), strB.substring(1));
correctly implement the rule