public static void reverseArray(int[] arr) {
for (int i = 0;i < arr.length / 2 ; i++) {
//arr[0]和arr[arr.length-1-0]交换
//arr[1]和arr[arr.length-1-1]交换
//arr[2]和arr[arr.lentth-1-2]
//...
int temp = arr[i];
arr[i] = arr[arr.length-1-i];
arr[arr.length-1-i] = temp;
}
} |
|