2019独角兽企业重金招聘Python工程师标准>>>
先说非计算机专业都能理解的。
int a = 10;
int b = 20;
方法一:
int c = a;
a = b;
b = c;
System.out.println("a="+a+",b="+b);
方法二:
a = a + b;
b = a - b;
a = a - b;
System.out.println("a="+a+",b="+b);
方法三:(需要有计算机基础)
a = a ^ b;
b = a ^ b;
a = a ^ b;
System.out.println("a="+a+",b="+b);
方法四:(一句话搞定)
b = ((a + b)b - (a = b))b;
System.out.println("a="+a+",b="+b);