获取最大相同子串
2013-01-02 08:29
162 查看
class StringTest3 { public static void main(String[] args) { String s1 = "Hello" ; String s2 = "ell"; System.out.println(getMaxSubString(s2,s1)); } /*获取最大相同子串*/ public static String getMaxSubString(String s1,String s2) { if (s1.length()<s2.length())//以短的作为子串 { String temp = s2; s2 = s1; s1 = temp; } /*短的子串长度依次递减1,然后遍历*/ for(int i=0;i<s2.length();i++) for (int j=0,k=s2.length()-i; k!=s2.length()+1;j++,k++ ) { String temp = s2.substring(j,k); //取从j字符开始的k个字符的子串 if (s1.indexOf(temp)!=-1) //找不到子串则还回-1 { return temp; } } return "";//即没有相同子串 } }
相关文章推荐
- 编写程序,获取两个字符串中最大相同子串
- java获取两个字符串中最大相同子串。第一个动作:将短的那个串进行长度一次递减的子串打印
- 获取两个字符串中最大的相同子串
- Java获取两个字符串中最大相同子串
- 获取两个字符串中最大相同子串
- Java获取两个字符串中最大相同子串的方法
- 黑马程序员_编写程序,获取两个字符串中最大相同子串
- String包装类应用之 获取两字符串的最大相同子串
- 获取两个字符串中最大的相同子串
- 获取两个字符串中最大相同子串的实现
- 获取两个字符串的最大相同子串
- 获取两个字符串中最大相同子串
- 编程实现获取两个字符串中最大相同子串
- 获取两个字符串中最大相同子串
- String小练习4-获取两个字符串中最大相同子串
- 获取两个字符串中最大相同子串
- java练习获取两个字符串的最大相同子串
- String去除字符串两端空格、将一个字符串进行反转、计算字符串中出现的的次数、获取两个字符串中最大相同字串
- 求两个字符串中的最大相同子串 SubString
- 两个字符串中最大的相同的子串(java编写)