不能出现第三个中间变量,字符串的交换.

今天百度知道遇到知友的提问,是这个问题,所以就回答了下,后面搜了下,还有各位高人牛逼算法,学习了。

public class Test24 
{ 
    public static void main(String... args) { 
        //abcdeabcd 
        String str1 = "abcd";  // abcdefg 
        String str2 = "abcdeeeabcd"; 
        str1 = ( str2 + str1 ).substring(0,(str2 + ( str2 = str1)).lastIndexOf(str1)) ; 
        System.out.println("str1: " + str1 + "," + "str2: " + str2); 
    } 
}
//author kf156 
  
String str1 = "abcd";  
String str2 = "efg"; 
str1 = str2 + ((str2 = str1) == null ? "" : ""); 
System.out.println(str1); 
System.out.println(str2);
//haojia0716

String s1 = "123";
String s2 = "456";
s1 = s2 + (s2 = s1).replaceAll(".", "");
System.out.println(s1);
System.out.println(s2);


你可能感兴趣的:(不能出现第三个中间变量,字符串的交换.)