代码:
public static void reverse(int[]arr) {
int left = 0;
int right = arr.length-1;
while(left<right) {
int tmp=arr[left];
arr[left] = arr[right];
arr[right] = tmp;
left++;
right--;
}
}
public static void main(String[] args) {
int[]arr = {8,7,6,5,4,3,2,1,0};
reverse(arr);
System.out.println(Arrays.toString(arr));
}
运行结果: