-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayReverse.java
More file actions
29 lines (25 loc) · 841 Bytes
/
ArrayReverse.java
File metadata and controls
29 lines (25 loc) · 841 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
import java.util.Arrays;
public class ArrayReverse {
// function that reverses array and stores it in another array
static void reverse(int arr[], int size)
{
int[] newArr = new int[size];
int j = size;
for (int i = 0; i < size; i++) {
newArr[j - 1] = arr[i];
j = j - 1;
}
// printing the reversed array
/*System.out.println("\nReversed array is: \n");
for (int k = 0; k < size; k++) {
System.out.println(newArr[k]);
} */
System.out.println("Reversed array is: " + Arrays.toString(newArr));
}
public static void main(String[] args)
{
int [] arr = {10, 20, 30, 40, 50};
System.out.println("Original Array is: " + Arrays.toString(arr));
reverse(arr, arr.length);
}
}