java基礎之陣列
阿新 • • 發佈:2018-12-09
public static void main(String[] args) { int[] arr = new int[]{34, 23, 56, 21, 19,68,10}; System.out.print("反轉前:"); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i]+" "); } for (int minIndex = 0, maxIndex= arr.length-1;minIndex<maxIndex;minIndex++,maxIndex--) {int temp = arr[minIndex]; arr[minIndex]=arr[maxIndex]; arr[maxIndex]=temp; } System.out.println(" "); System.out.print("反轉後: "); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i]+" "); } }