已有数组保存1,5,9,3,5,7,请颠倒数组元素的存放位置并输出,注意:颠倒后的数组{7,5,3,9,5,1},控制台输出:7 5 3 9 5 1
int arr2[]=new int[]{1,5,9,3,5,7};
for (int i = 0; i <arr2.length/2; i++) {
int temp=arr2[i];
arr2[i]=arr2[arr2.length-i-1];
arr2[arr2.length-i-1]=temp;
}
for (int i = 0; i <arr2.length; i++) {
System.out.print(" "+arr2[i]);
}
System.out.println();