本帖最后由 谭培龙 于 2012-7-27 00:51 编辑
- class StringTest3
- {
- public static String getMaxSubString(String s1,String s2)
- {
- String max="",min ="";
- max = (s1.length()>s2.length())?s1:s2;
- min = (max==s1)?s2:s1;
- for (int x=0;x<min.length() ;x++ )
- {
- for (int y=0,z=min.length()-x;z!=min.length() ;y++,z++ )
- {
- String temp=min.substring(y,z);
- //System.out.println(temp);
- if(max.contains(temp))//if(indexOf(temp)!=-1)
- return temp;
- }
- }
- return "";
- }
- public static void main(String[] args)
- {
- String s1="abcwerthelloyuireu";
- String s2="cbhellobnm";
- System.out.println(getMaxSubString(s1,s2));
- }
- }
复制代码 1,内for循环里面的Z代表什么?
2,String temp=min.substring(y,z);//这句话是什么意思?
3,return "";这里可以把方法改成void这里不写吗? |