package com.itcast.day06;
import java.util.Arrays;
public class Practice03 {
public static void main(String[] args) {
int[] arr = {41, 52, 72, 46, 86, 79};
reserve(arr);
}
public static void reserve(int[] arr) {
// 定义一个中间变量,相当于一个容器,达到交换数据的目的
for (int start = 0, end = arr.length - 1; start <= end; start++, end--) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
}
System.out.println(Arrays.toString(arr));
}
}
|
|