java 数组反转

1585364631
2023-02-18 / 0 评论 / 156 阅读 / 正在检测是否收录...

java数组反转

    private static int[] extracted(int[] arr) {
        for (int start = 0, end = arr.length - 1; start < end; start++, end--)    {
            arr[start] = arr[start] ^ arr[end];
            arr[end] = arr[start] ^ arr[end];
            arr[start] = arr[start] ^ arr[end];
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] arr = {11,22,33,44,55};
        int[] arr1 = extracted(arr);
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr[i]);
        }
    }

55
44
33
22
11

进程已结束,退出代码0

0

评论 (0)

取消