Array: Reverse an array

Question: Write a program to reverse an array

Example:

original array: {1,2,3,4,5}

Output:
5,4,3,2,1

 public static int[] reverseArray (int [] array){
        int [] newArray= new int[array.length];
        for (int i=0, j=(array.length-1); i< array.length; i++, j--){
            newArray[j]= array[i];
        }
        return newArray;
    }

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close