思路如图:
代码如下:
package com.java.day02; // 数组反转 public class ArrayReversed { public static void main(String[] args) { int[] array = new int[]{10, 20, 30, 40, 50}; for (int i = 0; i < array.length; i++) { System.out.println("正序排列的:" + array[i]); } System.out.println("************************"); for (int min = 0, max = array.length - 1; min < max; min++, max--) { int temp = array[min]; array[min] = array[max]; array[max] = temp; } for (int i = 0; i < array.length; i++) { System.out.println("倒序排列的:" + array[i]); } } }