-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseArray.java
More file actions
33 lines (33 loc) · 886 Bytes
/
reverseArray.java
File metadata and controls
33 lines (33 loc) · 886 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
29
30
31
32
33
public class reverseArray {
public static void main(String[] args){
int[] arr={1, 2, 3, 4};
int[] ar = new int[arr.length];
int x=0;
for(int i=(arr.length-1);i>=0;i--){
ar[x] = arr[i];
System.out.print(ar[x]+" ");
x++;
}
}
}
//recursion method
/*
public class reverseArray {
public static void reverse(int arr[], int initialInd, int len)
{
int temp;
if (initialInd >= len)
return;
temp = arr[initialInd];
arr[initialInd] = arr[len];
arr[len] = temp;
reverse(arr, initialInd+1, len-1);
}
public static void main(String[] args){
int[] arr={1, 2, 3, 4};
reverse(arr,0,arr.length-1);
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
}
}*/