| package com.guoba.array; |
| |
| public class Demo04 { |
| public static void main(String[] args) { |
| int[] arr = {1,2,3,4,5,6}; |
| |
| for (int i : arr) { |
| System.out.println(i); |
| } |
| System.out.println("========================"); |
| |
| int[] reverse = reverse(arr); |
| printArray(reverse); |
| } |
| |
| |
| public static void printArray(int[] arr){ |
| for (int j = 0; j < arr.length; j++) { |
| System.out.print(arr[j]+" "); |
| } |
| } |
| |
| |
| public static int[] reverse(int[] arr){ |
| int[] result = new int[arr.length]; |
| |
| |
| for (int i = 0,j = result.length-1;i < arr.length;i++,j--) { |
| result[j] = arr[i]; |
| } |
| return result; |
| } |
| |
| } |
| |