1.输入元素反转:如对int[] arr = {1,10,5,8,7,3,9}; 将其进行逆序排列 ——数组折半,对应位置交换
1 package cn.test.array; 2 3 public class ArrayReverseTest { 4 public static void main(String[] args) { 5 int[] arr = {1,10,5,8,7,3,9}; 6 int len = arr.length-1; 7 for (int i = 0; i < len/2; i++) { 8 int temp = arr[i]; 9 arr[i] = arr[len-i]; 10 arr[len-i]=temp; 11 } 12 for(int i:arr){ 13 System.out.print (i+" "); 14 } 15 } 16 }