跟HJ75一样一样 只不过这个把字符串输出出来,HJ75知识输出字符串的长度值
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String a = in.nextLine();
String b = in.nextLine();
if (a.length() > b.length()) {
String temp = a;
a = b;
b = temp;
}
int max = 0;
String res="";
for (int i = 0; i <= a.length() - 1; i++) {
for (int j = i; j <= a.length() - 1; j++) {
String temp = a.substring(i,
j + 1); //因为我要截取[i,j]之间的字符串包括i,j
if (b.contains(temp)) {
if(temp.length()>max){
max=temp.length();
res=temp;
}
}
}
}
System.out.println(res);
}