import java.util.Scanner; public class GetCommonStr { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str1 = scan.nextLine(); String str2 = scan.nextLine(); String result = getCommonStr(str1,str2); System.out.println(result); } private static String getCommonStr(String str1, String str2) { str1 = str1.toLowerCase(); str2 = str2.toLowerCase(); for (int i = 0; i < str2.length(); i++) { for (int j = 0,k = str2.length()-i; k != str2.length() + 1; j++,k++) { String temp = str2.substring(j, k); if(str1.contains(temp)) return temp; } } return null; } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-06 19:40:21