Skip to content

Commit

Permalink
Changed reverse array
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshgaigawali committed Oct 30, 2024
1 parent 81ad75a commit fa626a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions problems/ReverseArray.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* Program to Create the Array in Reverse Order. */
package problems;

public class ReverseArray {
Expand All @@ -7,13 +8,12 @@ public static void main(String[] args) {
int arr1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

int arr2[] = new int[arr1.length];
int in = 0;
for (int i = arr1.length; i >= 0; i--) {
arr2[in] = arr1[i];
in++;
}
int index = arr1.length;

System.out.println(arr2.length);
for (int i = 0; i < arr1.length; i++) {
arr2[--index] = arr1[i];
System.out.print(arr2[index] + " ");
}

}
}

0 comments on commit fa626a7

Please sign in to comment.