扑克牌交换经典案例

若a1 = 10,a2 = 20,求让a1= 20,a2 = 10:

 

 方法一:

var a1=10;
var a2=20;
 a3=a1;
 a1=a2;
 a2=a3;

 

方法二:
a1=a1+a2;
a2=a1-a2;
a1=a1-a2;

 



方法三:
a=a^b;
b=a^b;  //b = a^b^b
a=a^b;  //a = a^a^b

 

posted @ 2016-12-20 22:17  明明一颗大白菜  阅读(373)  评论(0编辑  收藏  举报
<-- -->