- public class StringTest {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String s1="sasasaworklkfdkfkd";
- String s2="fddworkitmh";
- show(getMaxSubString(s1,s2));
- }
- public static String getMaxSubStrng(String s1,String s2){
- for(int x=0;x<s2.length();x++){
- //下面的这个判断条件有点抽象,理解了半天还是没理解清楚,有谁给我解释一下?
- for(int y=0,z=s2.length()-x;z!=s2.length()+1;y++,z++){
- String temp =s2.substring(y,z);
- if(s1.contains(temp)){
- return temp;
- }
- }
- }
- return "";
- }
-
- public static void show(String str){
- System.out.println(str);
- }
- }
复制代码
|