反转:就是把元素对调
最快的方式就是首尾交换
public static void main(String[] args){
int[] arr = {11,22,33,44,55};
//反转数组
for (int i = 0; i < arr.length/2; i++) {
//arr[0]和arr[arr.length-1]交换
//arr[1]和arr[arr.length-1-1]交换......
int temp = arr[i];
arr[i] = arr[arr.length-1-i];
arr[arr.length-1-i] = temp;
}
//遍历数组
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}