java交换两个变量的值(方法介绍)
//方法1:
int A = 3;
System.out.println("a:"+A);
int B = 4;
System.out.println("b:"+B);
A = A ^ B;
B = B ^ A;
A = A ^ B;
System.out.println("a:" + A + ",b:" + B);
//异或方法转换int数值
//方法2:
double A1 = 3.3;
double B1 = 2.1;
double temp = A1;
A1=B1;
B1=temp;
System.out.println("a1:" + A1 + ",b1:" + B1);
//中间值变量交换double值
//方法3:
double A2=4.3;
double B2=-3.1;
A2=A2+B2;
B2=A2-B2;
A2=A2-B2;
System.out.println("a2:" + A2 + ",b2:" + B2);
//利用加减运算交换double值
大家还有什么好的方式,就留在评论里吧.