package com.miya.algorithm.sort;
/**
* Created by kayle on 16/9/8.
* 交换数组两个元素位置
*/
public class Change {
public static void main(String[] args) {
int x = 3, y = 5;
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
test(arr, x, y);
}
public static void test (int[] arr, int x, int y) {
int a = arr[x];
int b = arr[y];
a = a+b;
b = a-b;
a = a-b;
arr[x] = a;
arr[y] = b;
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
网友评论