- class ReverseArray {
- public static void main(String[] args) {
- int[] arr = {1,2,3,4,5,6,7,8};
- arr = ReverseArray(arr);
- printArray(arr);
- }
-
- public static int[] ReverseArray(int[] arr) {
- int[] arr1 = new int[arr.length];
- for (int i = 0; i < arr.length ;i++ ) {
- arr1[arr.length - 1 - i] = arr[i];
-
- }
- return arr1;
-
- }
-
- public static void printArray(int[] arr) {
- for (int i = 0; i < arr.length ;i++ ) {
- System.out.print(arr[i] + " ");
- }
- System.out.println();
- }
- }
复制代码
|