马州州 发表于 2012-8-5 19:20
你这代码里面带着HTML代码,看的头疼,你重新编辑一下吧 - class Demo4
- {
- public static void sop(String str)
- {
- System.out.println(str);
- }
- public static void main(String[] args)
- {
- String s1 = "abcwerthelloyuiodef";
- String s2 = "cvhellobnm";
-
- sop(getMaxSubString(s1,s2));
- }
- public static String getMaxSubString(String s1,String s2)
- {
- String max = "";//长串
- String min = "";//短串
- max=(s1.length()>s2.length())?s1: s2;//如果s1长度s2长度,那么赋值s1否则赋值s2
- min = (max==s1)?s2: s1;//如果max和s1相等,那么赋值s2,否则赋值s1
- //下面的是循环打印s2,
- //y是首位,z是末尾
-
- for (int x = 0;x<min.length();x++)
- {
- for (int y = 0,z = min.length()-x; z!=min.length()+1 ; y++,z++ )
- {
- String temp = min.substring(y,z);
- //sop("trmp="+trmp);
- if(max.indexOf(temp)!=-1)
- //这里,如果返回类型是void的话 这里怎么写呢?
- return temp;
- }
- }
- return "";
- }
- }
复制代码 |