本帖最后由 陈嘉宾 于 2012-5-28 22:51 编辑
这段代码越看越迷糊啊。。for(int x=0;x<s2.length();x++)
{
for (int y=0,z=s2.length()-x;z!=s2.length()+1 ;y++,z++ )
{
String temp =s2.substring(y,z);
上代码求解答
class stringtest3
{
public static String getMaxSubString(String s1,String s2)
{
for(int x=0;x<s2.length();x++)
{
for (int y=0,z=s2.length()-x;z!=s2.length()+1 ;y++,z++ )
{
String temp =s2.substring(y,z);
if(s1.contains(temp))
return temp;
}
}
return "";
}
public static void main(String[] args)
{
String s1="avcwerthelloyuiodef"
String s2="cvhellobnm"
sop(getMaxSubString(s1,s2))
}
public static void sop()String str)
{
System.out.println(str);
}
} |