java取两个字符串的最大交集
本文实例讲述了java取两个字符串的最大交集的实现方法,分享给大家供大家参考。具体实现方法如下:
public class game13
{
public static void main(string[] args)
{
string s1 = "135adbfg67";
string s2 = "125dbf59";
string s3 = s2;
int begin = 0;
int end = s2.length();
int i = 1;
while (!s1.contains(s3))
{
if (end == s2.length())
{
begin = 0;
end = (s2.length()) - (i++);
}
else
{
begin++;end++;
}
s3 = s2.substring(begin, end);
system.out.println(s3);
system.out.println("--------");
}
system.out.println(s3);
}
}
package com.itheima.net;
public class game15
{
public static void main(string[] args)
{
string s1 = "135adbfg67";
string s2 = "125dbf59";
method(s2, s1);
}
public static void method(string max, string min)
{
if (max.length() < min.length())
{
string s = max;
max = min;
min = s;
}
string substr = min;
for (int begin = 0, end = min.length(), i = 1; !max.contains(substr); substr = min.substring(begin, end))
{
if (end == min.length())
{
begin = 0;
end = (min.length()) - (i++);
}
else
{
begin++;
end++;
}
system.out.println(substr);
system.out.println("--------");
}
system.out.println(substr);
}
}
希望本文所述对大家的java程序设计有所帮助。
上一篇: ThinkPHP组装分页字符串
下一篇: 如何检查叶绿体基因组组装结果的准确性v1