代码如下,我想问得的是getsubstring函数中的return "";代码有什么作用,我编码的时候没有写,jvm提示我编译失败,缺少返回语句,但我的return str;不就是返回语句么?求解释
public static String getsubstring(String s1,String s2)
{ String max="",min="";
max=(s1.length()>s2.length())?s1:s2;
min=(max==s1)?s2:s1;
for (int x=0;x<min.length() ;x++ )
{ for (int y=0,z=min.length()-x;z!=min.length()+1 ;y++,z++ )
{
String str=min.substring(y,z);
if(max.contains(str))
return str;
}
}
return "";
}
public static void main (String[] args)
{
String s1="dfjdlgjladoieiuohello0";
String s2="hello0dfjlangngaolu";
System.out.println(getsubstring(s1,s2));
} |