1 package shuzu; 2 3 public class ShuZu { 4 5 public static void main(String[] args) 6 { 7 //反转排序 8 int arr[] = {6,7,2,9,3,5,4,1,8}; 9 10 for(int i = 0; i < arr.length/2; i++)//两两交换,只需循环数组长度的一半 11 { 12 int temp = arr[i];//声明中间变量,进行数中组两数交换 13 arr[i] = arr[arr.length - 1 - i]; 14 arr[arr.length - 1- i] = temp; 15 16 } 17 //遍历数组输出数组元素值 18 for(int x : arr) 19 { 20 System.out.print(x); 21 } 22 } 23 24 }