revert int array - Java java.lang

Java examples for java.lang:int Array

Description

revert int array

Demo Code


import java.lang.reflect.Array;

public class Main{
    public static void main(String[] argv) throws Exception{
        int[] array = new int[]{34,35,36,37,37,37,67,68,69};
        revert(array);//from  w  ww . j  a va  2 s .  c o  m
    }
    public static void revert(int[] array) {

        int[] temp = clone(array);
        for (int i = 0; i < array.length; i++) {
            array[i] = temp[array.length - 1 - i];
        }
    }
    public static int[] clone(int[] array) {
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        return copy;
    }
}

Related Tutorials