int a,b;
a=5;b=10;
a=a-b; //a=-5,b=10
b=b+a; //a=-5,b=5
a=b-a; //a=10,b=5
System.out.println("a="+a);
System.out.println("b="+b);
a=a+b; //a=15,b=10
b=a-b; //a=15,b=5
a=a-b; //a=10,b=5
System.out.println("a="+a);
System.out.println("b="+b);
a=5;b=10;
a=a^b; //a=15,b=10
b=a^b; //a=15,b=5
a=a^b; //a=10,b=5
System.out.println("a="+a);
System.out.println("b="+b);
a=5;b=10;
a=a*b; //a=50,b=10
b=a/b; //a=50,b=5
a=a/b; //a=10,b=5
System.out.println("a="+a);
System.out.println("b="+b);
a=5;b=10;
a = a + b - (b = a);
System.out.println("a="+a);
System.out.println("b="+b);
a=5;b=10;
b = a + (a = b)*0;
System.out.println("a="+a);
System.out.println("b="+b);
Java中不引入第三个变量实现两个变量值的交换
最新推荐文章于 2022-10-28 16:41:31 发布