Created
July 20, 2018 10:06
-
-
Save julianjupiter/37227e768fc6035276da79ef31a027d0 to your computer and use it in GitHub Desktop.
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
| public class ArrayOfIntegerReverse { | |
| public static void main(String[] args) { | |
| int[] intArr = new int[] {1, 2, 3, 4, 5}; | |
| int[] newIntArr = reverse(intArr); | |
| for (int i = 0; i < intArr.length; i++) { | |
| System.out.print(intArr[i] + " "); | |
| } | |
| System.out.println(); | |
| for (int i = 0; i < newIntArr.length; i++) { | |
| System.out.print(newIntArr[i] + " "); | |
| } | |
| System.out.println(); | |
| } | |
| public static int [] reverse(int[] intArr) { | |
| int intArrLength = intArr.length; | |
| int[] newIntArr = new int[intArrLength]; | |
| for (int i = 0; i < intArrLength; i++) { | |
| newIntArr[i] = intArr[intArrLength - 1 - i]; | |
| } | |
| return newIntArr; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment