逆数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

412
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
逆数组
/** 来自 NowJava.com**/

//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        Object[] arr = new String[] { "1", "abc", "level", null,

                "nowjava.com", "asdf 123" };

        System.out.println(java.util.Arrays.toString(converseArray(arr)));

    }


    public static Object[] converseArray(Object[] arr) {

        Object para = null;

        for (int i = 0; i <= arr.length / 2; i++) {

            para = arr[i];

            arr[i] = arr[arr.length - 1 - i];

            arr[arr.length - 1 - i] = para;

        }

        return arr;//来自 nowjava - 时  代  Java

    }


    public static int[] converseArray(int[] arr) {

        int para;

        for (int i = 0; i <= arr.length / 2; i++) {

            para = arr[i];

            arr[i] = arr[arr.length - 1 - i];

            arr[arr.length - 1 - i] = para;

        }

        return arr;

    }


    public static char[] converseArray(char[] arr) {

        char para;

        for (int i = 0; i <= arr.length / 2; i++) {

            para = arr[i];

            arr[i] = arr[arr.length - 1 - i];

            arr[arr.length - 1 - i] = para;

        }

        return arr;

    }


    public static byte[] converseArray(byte[] arr) {

        byte para;

        for (int i = 0; i <= arr.length / 2; i++) {

            para = arr[i];

            arr[i] = arr[arr.length - 1 - i];

            arr[arr.length - 1 - i] = para;

        }

        return arr;

    }


    public static short[] converseArray(short[] arr) {

        short para;

        for (int i = 0; i <= arr.length / 2; i++) {

            para = arr[i];

            arr[i] = arr[arr.length - 1 - i];

            arr[arr.length - 1 - i] = para;

        }

        return arr;

    }


    public static long[] converseArray(long[] arr) {

        long para;

        for (int i = 0; i <= arr.length / 2; i++) {

            para = arr[i];

            arr[i] = arr[arr.length - 1 - i];

            arr[arr.length - 1 - i] = para;

        }

        return arr;

    }


    public static float[] converseArray(float[] arr) {

        float para;

        for (int i = 0; i <= arr.lengt
展开阅读全文