public class Demo {
public static void main(String[] args) {
int a = 3;//0011 二进制表示
int b = 5;//0101
a = a ^ b;//0110 6
b = a ^ b;//0101 0011 3 异或算法
a = a ^ b;//0110 0011 = 0101 5
System.out.println("a="+a+"b="+b);
int a = 3;
int b = 5;
int c = a;
a = b;
b = c;
System.out.println("a="+a+"b="+b);
int a = 3;
int b = 5;
int c = a + b;
b = c - b;
a = c - b;
System.out.println(a+","+b);
}
}
java交换两个数的值的三种方法
最新推荐文章于 2024-09-27 23:37:45 发布