java数组反转

package array;

public class ArrayDemo5 {
    public static void main(String[] args) {
        //反转数组
        int[] arrays = {1,2,3,4,5};

        printArrays(reverse(arrays));
    }
    public static int[] reverse(int[] array){
        int[] result = new int[array.length];
        //反转操作
        for (int i = 0,j=result.length-1; i < array.length; i++,j--) {
            result[j] = array[i];
        }
        return result;
    }
    public static void printArrays(int[] arrays){
        for (int i = 0; i < arrays.length; i++) {
            System.out.println(arrays[i]);
        }
    }

}

java数组反转

上一篇:递归函数概念


下一篇:leetcode 056: 合并区间