Created
January 29, 2014 08:06
-
-
Save pepet96/8683679 to your computer and use it in GitHub Desktop.
Reverse Order Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| import java.util.Arrays; | |
| public class Arrayreverse { | |
| public static void main (String [] args) { | |
| Scanner input = new Scanner(System.in); | |
| int positions = input.nextInt(); | |
| int[] myArray = new int[positions]; | |
| for (int i = 0; i < myArray.length; i++){ | |
| myArray[i] = input.nextInt(); | |
| } | |
| int[] reversed = reverseArray(myArray); | |
| System.out.println(Arrays.toString(reversed)); | |
| } | |
| public static int[] reverseArray(int[] myArray) | |
| { | |
| int[] reversedData = new int[myArray.length]; | |
| int i; | |
| for(i=0; i < myArray.length; i++){ | |
| reversedData[i] = myArray[(myArray.length - i -1)]; | |
| } | |
| return reversedData; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment