- class StringTest4
- {
- public static void main(String[] args)
- {
- String s1="abcwerthelloyuiodef";
- String s2="cvhellobnm";
- System.out.println(getMaxSubString(s1,s2));
- }
-
- 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);
- System.out.println(temp);
- if(s1.contains(temp))//if(s1.indexOf(temp)!=-1)
- return temp;
- }
- }
- return "";//这里不太明白,为什么非得写它?上面不是已经return过了吗?
- }
- }
复制代码 |
|