CODE ---->
String temp, output = null, target1 = null, target2 = null;
int max = 0;
if (input1.length() <= input2.length())
{
target1 = input1;
target2 = input2;
} else
{
target1 = input2;
target2 = input1;
}
for (int i = target1.length() - 1; i >= 0; i--)
{
for (int j = 0; j <= i; j++)
{
temp = target1.substring(j, i + 1);
System.out.println(temp);
if (target2.indexOf(temp) >= 0)
{
if (temp.length() > max)
{
output = temp;
max = temp.length();
}
}
}
}
output1=max;(//try)
System.out.println(max+" "+output);
No comments:
Post a Comment