本帖最后由 曹睿翔 于 2012-11-29 21:43 编辑
- class StringTest4
- {
- public static void main(String[] args)
- {
- sop(getMaxSubString("fdsaabcdefgsafvg","asabcdefghh"));
- }
- //获取两个字符串最大相同子串
- public static String 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;z++,y++ )
- {
- String temp = min.substring(y,z);
- if (max.contains(temp))
- return temp;
- }
- }
-
- return "";
- }
- public static void sop(Object obj){
-
- System.out.println(obj);
- }
- }
复制代码 其中在双重for循环中返回一个 temp;
又在成员代码块return一个 " ",
getMaxSubString是怎么接收到temp的?
不明白,求解 |
|