作者:love乄鮰 | 来源:互联网 | 2023-08-26 18:26
1.创建一个临时变量存储两个中某个值privatevoidswap(){intx10;inty100;inttempx;xy;ytemp;}2.两数相加保存和值privatevo
1.创建一个临时变量存储两个中某个值
private void swap(){int x = 10;int y = 100;int temp = x;x = y;y = temp;}
2.两数相加保存和值
private void swap(){int x = 10;int y = 100;x = x + y;y = x - y;x = x - y;}
3.两数异或保存两数状态
private void swap(){int x = 10;int y = 100;x = x ^ y;y = x ^ y;x = x ^ y;}