标签:int ++ public length min 最大字串 get nta contains
public class StringTest3 {
public static void main(String[] args) {
String str1 = "helabchaahha";
String str2 = "boodoabcdworldhhha";
String str3 = getMaxStr(str1,str2);
System.out.println(str3);
}
public static String getMaxStr(String s1,String s2) {
String min=null,max=null;
max = (s1.length()>s2.length())?s1:s2;
min = (max.equals(s1))?s2:s1;
for(int x=0;x<min.length();x++) {
for(int m=0,n=min.length()-x;n!=min.length()+1;m++,n++) {
String s3 = max.substring(m, n);
//System.out.println(s3);
if(s1.contains(s3)) {
return max+" "+min+"\n"+"最大的子串为"+s3;
}
}
}
return null;
}
}
标签:int ++ public length min 最大字串 get nta contains
原文地址:http://www.cnblogs.com/Candicecl/p/7773730.html