public static void main(String[] args) {
String s1 = "abcdhelloefg";
String s2 = "efhelloop";
String s = getMaxstring(s1, s2);
System.out.println("最大子串是" + s);
int i = 11;
int a = 2;
int v = i > a ? i : a;
System.out.println(v);
}
private static String getMaxstring(String s1, String s2) {
String max = " ";
String min = " ";
max = (s1.length() > s2.length() ? s1 : s2);
min = (max == s1 ? s2 : s1);
System.out.println(min);
for (int i = 0; i < min.length(); i++) {
for (int j = 0, z = min.length() - i; z != min.length() + 1; j++, z++) {
// String temp = max.substring(j, z);
// if (max.contains(temp)) {
// return temp;
// }
/*
* 想要得到相同的子字符串,就要用一个字符串变量保存截取的字符
*/
String mins = min.substring(j, z);
if (max.contains(mins)) {
return mins;
}
}
}
return null;
}作者: 吴小东 时间: 2012-6-10 13:26
我把你的错误简化了一下 你看看下面就清楚了 每循环一次你的min值都会变化,循环条件一直在变
String min ="adfsdfsdf";
for (int i = 0;i<min.length ;i++ )
{
min = min.substring(i,i+10);
}