1、借助变量temp
int a = 5;
int b = 10;
int temp;
temp = a;
a = b;
b = temp;
System.out.println("a=" + a); // a=10
System.out.println("b=" + b); // b=5
2、加法(不使用变量)
int a = 5;
int b = 10;
a = a + b;
b = a - b;
a = a - b;
System.out.println("a=" + a); // a=10
System.out.println("b=" + b); // b=5
3、异或(相同为0,不相同为1)
int a = 5;
int b = 10;
a = a^b;
b = a^b;
a = a^b;
System.out.println("a=" + a); // a=10
System.out.println("b=" + b); // b=5