Skip to content

Instantly share code, notes, and snippets.

@julianjupiter
Created July 20, 2018 10:06
Show Gist options
  • Select an option

  • Save julianjupiter/37227e768fc6035276da79ef31a027d0 to your computer and use it in GitHub Desktop.

Select an option

Save julianjupiter/37227e768fc6035276da79ef31a027d0 to your computer and use it in GitHub Desktop.
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