本帖最后由 蒋淑静 于 2013-12-14 20:22 编辑
- package _2012;
- class StringTest1
- {
- public static void main(String[] args)
- {
- String s1="abcwerthelloyuiodef";
- String s2="cvhellobnm";
- getMaxSubString(s1,s2);
- }
- public static String getMaxSubString(String s1,String s2){
- String max="";
- String 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()+1);y++,z++){
- String temp=min.substring(y,z);
- if(max.contains(temp)){
- return temp;
- }
- }
-
- }
- return "";
- }
-
- }
复制代码
for循环的条件语句可以这样写吗,我编译时会报错,不知道怎么该,for(int y=0,z<min.length()-x;z!=(min.length()+1);y++,z++) |