本帖最后由 冯海霞 于 2012-11-2 15:20 编辑
class StringTest3
{
public static String getMaxSubString(String s1,String s2)
{
String max = "",min = "";
max = (s1.length()>s2.length())?s1: s2;
min = max==s1?s2: s1;
sop(max+"..."+min);
for(int x=0; x<min.length();x++)
{
for(int y=0, z=min.length()-x; z!=min.length()+1; y++,z++)
{
String temp = min.substring(y,z);
if(max.contains(temp));
return temp;
}
}
return "";
}
public static void main(String[] args)
{
String s1 = "abcsdfshellovvggfdfd";
String s2 = "dferfhellogbffd";
sop(getMaxSubString(s1,s2));
}
public static void sop(String str)
{
System.out.println(str);
}
}
希望return temp值为hello |
|