forked from Kritikaadhikarii/HacktoberFest2024Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Reversal.java
More file actions
32 lines (25 loc) · 753 Bytes
/
Array_Reversal.java
File metadata and controls
32 lines (25 loc) · 753 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
public class Array_Reversal {
public static void printArray(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static void ReverseArray(int [] number, int start, int end){
while(start<end){
int temp = number[start];
number[start] = number[end];
number[end] = temp;
start++;
end--;
}
}
public static void main(String[] args) {
int[] arr = {1,2,3,4,5,6,7};
System.out.println("Original Array");
printArray(arr);
System.out.println("Reversed Array");
ReverseArray(arr,0,arr.length-1);
printArray(arr);
}
}