-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayrev.java
More file actions
28 lines (25 loc) · 769 Bytes
/
Arrayrev.java
File metadata and controls
28 lines (25 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
import java.util.ArrayList.*;
public class Arrayrev {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = s.nextInt();
reverseArray(arr);
for (int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");
}
// Method to reverse the array
static void reverseArray(int[] arr) {
// Write your code here
int b[] = new int[arr.length];
for (int i = arr.length-1; i >= 0; i--){
b[arr.length-1-i]= arr[i];
}
for (int i = 0; i< arr.length; i++){
arr[i]= b[i];
}
}
}