public void printArray(char[] array)
{
for (int i = array.length - 1; i >= 0; i--)
{
System.out.print(i);
}
System.out.println();
}
public char[] commonSuffix(char[] x, char[] y)
{
int smallStringLength = Math.min(x.length, y.length);
char[] z = new char[smallStringLength];
boolean suffix = true;
for (int i = 0; i < smallStringLength; i++)
{
if ((x[x.length - 1 - i] == y[y.length - 1 - i]) && suffix)
{
z[i] = x[x.length - 1 - i];
}
else
{
z[i] = ' ';
suffix = false;
}
}
return z;
}
So printArray in this case prints the array out backwards as we check the string backwards to see if the suffix exists. We add spaces to the rest of the array the moment that a mutual character does not exist.