方法一:逆序翻转
public class arrayreverse{
public static void main(String[] args){
int i = 0, j = 0;
int [] arr = {11,22,33,44,55,66};
int[] arr1 = new int[arr.length];
for(i = arr.length - 1,j = 0;i >= 0; i--,j++){
arr1[j] = arr[i];
}
arr = arr1; //将arr1的空间地址赋给arr,原来的arr空间被释放
for(j = 0; j < arr1.length; j++)
System.out.println(arr[j]);
}
}
方法二:找规律翻转
public class arrayreverse{
public static void main(String[] args){
int [] array = {11,22,33,44,55,66};
int temp,i;
for(i = 0;i < array.length/2;i ++){
temp = array[i];
array[i] = array[array.length - 1 - i];
array[array.length - 1 - i] = temp;
}
for(i = 0;i < array.length; i++)
System.out.println(array[i] + "\t");
}
}