两数交换的二种方法,就拿javascript脚本来说。
第一种方法:
<script type="text/javascript">
var x = 100;
var y = 200;
var c = x;
x = y;
y = c;
document.writeln("x=" + x + "<br />" + "y=" + y);
</script>
第二种方法:
<script type="text/javascript">
var x = 100;
var y = 200;
x = x + y;
y = x - y;
x = x - y;
document.writeln("x=" + x + "<br />" + "y=" + y);
</script>