数组

//数组是一个连续的存储空间

 

//两个数交换第一种方法(先加后减)

int a=6,b=9,temp;

temp=a+b;

a=temp-a;

b=temp-b;

System.out.println(String.format("a:%d,b:%d,temp:%d", a,b,temp));

第二种方法:纯互换

int a=6,b=9,temp;

temp=a;

a=b;

b=temp;

System.out.println(String.format("a:%d,b:%d,temp:%d", a,b,temp));

//排序

 

原文地址:https://www.cnblogs.com/-Zfd/p/6770331.html