日期:2014-05-20 浏览次数:20600 次
public static void main(String[] args) {
int[] arr0 = { 0, 1, 2 };
int[] arr1 = { 3, 4, 5 };
int size = arr0.length;
for (int i = 0; i < size; i++) {
System.out.print(arr0[i] + ",");
}
for (int i = 0; i < size; i++) {
if (i != size - 1) {
System.out.print(arr1[i] + ",");
} else {
System.out.println(arr1[i]);
}
}
System.out.println("-------------");
arrayExchange(arr0, arr1);
for (int i = 0; i < size; i++) {
System.out.print(arr0[i] + ",");
}
for (int i = 0; i < size; i++) {
System.out.print(arr1[i] + ",");
}
}
public static void arrayExchange(int[] arr0, int[] arr1) {
int length=arr0.length;
for(int i=0;i<length;i++){
arr0[i]=arr0[i]+arr1[i];
arr1[i]=arr0[i]-arr1[i];
arr0[i]=arr0[i]-arr1[i];
}
}