本帖最后由 淡淡柠檬茶 于 2014-6-13 23:41 编辑
class GetmaxSubstring
{
public static void main(String[] args)
{
String a1 = "asdaetsfaf";
String a2 = "geasdfaf";
System.out.println(getMaxSubstring(a2,a1));
//System.out.println("Hello World!");
}
public static void getMaxSubstring(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 temp = min.substring(y,z);
if(max.contains(temp))
return temp;
}
}
return "";
}
}
错误提示:
GetmaxSubstring.java:7: 错误: 此处不允许使用 '空' 类型
System.out.println(getMaxSubstring(a2,a1));
^
GetmaxSubstring.java:24: 错误: 对于结果类型为空的方法, 无法返回值
return temp;
^
GetmaxSubstring.java:27: 错误: 对于结果类型为空的方法, 无法返回值
return "";
^ |
|