From 82211e7b0d55d0bf441bef23c00d086bd22f48d0 Mon Sep 17 00:00:00 2001 From: Rishikesh Vilas Wagh <101021147+Rishiwagh@users.noreply.github.com> Date: Mon, 31 Oct 2022 23:13:12 +0530 Subject: [PATCH] Create array.java --- array.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 array.java diff --git a/array.java b/array.java new file mode 100644 index 0000000..e884740 --- /dev/null +++ b/array.java @@ -0,0 +1,45 @@ +// Iterative java program to reverse an +// array +public class GFG { + +/* Function to reverse arr[] from + start to end*/ + static void rvereseArray(int arr[], + int start, int end) + { + int temp; + + while (start < end) + { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + /* Utility that prints out an + array on a line */ + static void printArray(int arr[], + int size) + { + for (int i = 0; i < size; i++) + System.out.print(arr[i] + " "); + + System.out.println(); + } + + // Driver code + public static void main(String args[]) { + + int arr[] = {1, 2, 3, 4, 5, 6}; + printArray(arr, 6); + rvereseArray(arr, 0, 5); + System.out.print("Reversed array is \n"); + printArray(arr, 6); + + } +} + +// This code is contributed by Sam007