reversingArrays
This commit is contained in:
parent
0e13691185
commit
880f1d5854
BIN
ReverseArray/ArrayReversing.class
Normal file
BIN
ReverseArray/ArrayReversing.class
Normal file
Binary file not shown.
30
ReverseArray/ArrayReversing.java
Normal file
30
ReverseArray/ArrayReversing.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
public class ArrayReversing {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] intArr = { 1, 2, 3, 4, 5 };
|
||||||
|
Reverse(intArr);
|
||||||
|
Printing(intArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Reverse(int[] arr) {
|
||||||
|
// initiate the start and the end of the ArrayReversing
|
||||||
|
int start = 0;
|
||||||
|
int end = arr.length - 1;
|
||||||
|
|
||||||
|
while (start < end) {
|
||||||
|
int temp = arr[start];
|
||||||
|
arr[start] = arr[end];
|
||||||
|
arr[end] = temp;
|
||||||
|
// Moving pointers
|
||||||
|
start++;
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Printing(int[] arr) {
|
||||||
|
for (int x : arr) {
|
||||||
|
System.out.println(x + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user