方法1
/**
* @author Meowrain
* @version 1.0
*/
package com.meowrain;
public class Main{
public static void main(String[] args){
int[] arr = {11,22,33,44,55,66,77,88}; //定义一个存有8位数字的数组
for (int i = 0; i < arr.length / 2; i++) {
int temp = arr[arr.length - 1 - i]; //把末尾的数字存在临时变量里面
arr[arr.length - 1 - i] = arr[i];//把最后一个数字和第一个数字进行交换
arr[i] = temp;
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
方法2
/**
* @author Meowrain
* @version 1.0
*/
package com.meowrain;
public class Main {
public static void main(String[] args){
int [] arr1 = {11,22,33,44,55,66,77,88};
int [] arr2 = new int[arr1.length];
for (int i = arr1.length - 1,j = 0; i >= 0; i--,j++) {
arr2[j] = arr1[i];
}
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
}
}
}