public class DoubleNumberChange {
public static void main(String[] args) {
int a = 5;
int b = 4;
a = a + b;
b = a - b; // 9-4
a = a - b; // 9-5
System.out.println("a==" + a + " ,b==" + b); 數組
a = (a + b) - (b = a); //
System.out.println("a==" + a + " ,b==" + b); spa
a = b + 0 * (b = a); // 執行順序處理
System.out.println("a==" + a + " ,b==" + b); 字符串
//按位異或能夠用來使某些特定的位翻轉
//經過按位異或運算,能夠實現兩個值的交換,而沒必要使用臨時變量。
a ^= b; //此時的a 在我看來是中間變量 轉換器
b ^= a;
a ^= b;
System.out.printf("a = %d, b = %d\n", a, b); //調用 c語言
//方法四 字符串 數組
String s1 = "111", s2 = "222";
s1 = s1 + "," + s2;
s2 = s1.split(",")[0];
s1 = s1.split(",")[1];
System.out.printf("s1 = %s, s2 = %s\n", s1, s2);
//方法五 字符串 表達式(相似方法一)
String str1 = "aaa", str2 = "bbb";
str1 = str2 + ((str2 = str1) == "" ? "" : ""); //臨時的邏輯處理
System.out.printf("str1 = %s, str2 = %s\n", str1, str2); it
}
} class