Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions Java/Aayush Talreja/arrayReverse.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
public class arrayReverse{
static void reverseArray(int[]a, int n){
int[] b = new int[n];
int j = n;

for(int i=0; i<n; i++){
b[j-1] = a[i];
j = j-1;
}

System.out.print("Reversed Array: ");
for(int k=0; k<n; k++){
System.out.print(b[k] + " ");
}
}

public static void main(String[] args) {
int [] arr = {10, 20, 30, 40, 50};
reverseArray(arr, arr.length);
}
}
// Reversing an array using Java collections
import java.util.*;
public class reversingArray {
static void reverse(Integer a[])
{
Collections.reverse(Arrays.asList(a));
System.out.println(Arrays.asList(a));
}
public static void main(String[] args)
{
Integer [] arr = {10, 20, 30, 40, 50};
reverse(arr);
}
}