Hi.
I know about the FAQ and this is indeed partially homework related. I'm not asking someone for a solution but rather a direction. I need to write a recursive function that gets two strings and checks whether they differ by only one bit. The thing is the skeleton of the function is already given (you can assume that the stings only contain 0's and 1's and are of the same length):
boolean IsGray(String s1,String s2)
{
if ((s1.length()==0) || (s2.length()==0))
return false;
if (s1.charAt(0)!=s2.charAt(0))
{
// Do stuff
}
else
{
// Do stuff
}
}
I only got here:
boolean IsGray(String s1,String s2)
{
if ((s1.length()==0) || (s2.length()==0))
return false;
if (s1.charAt(0)!=s2.charAt(0))
{
boolean res=IsGray(s1.substring(1),s2.substring(1));
if (res)
return false;
else
return true;
}
else
{
return IsGray(s1.substring(1),s2.substring(1));
}
}
As expected this code only checks if they differ by an odd number of bits.
Any suggestions, tips and such would be greatly appreciated.