Java_数组逆序操作:定义长度为10的数组,将数组元素对调,并输出对调前后的结果

import java.util.Arrays;

/**
 * 数组逆序操作:定义长度为10的数组,将数组元素对调,并输出对调前后的结果。
 * 
 * @author Chill_Lyn
 *
 */
public class ArrayReverseOrder {

	public static void main(String[] args) {
		int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		int temp = 0;
		System.out.println(Arrays.toString(a));

		for (int i = 0; i < a.length / 2; i++) {
			temp = a[i];
			a[i] = a[a.length - 1 - i];
			a[a.length - 1 - i] = temp;
		}
		System.out.println(Arrays.toString(a));

	}

}

你可能感兴趣的:(Java_基础)