**************************************************
Java Programs for programming and coding interview
**************************************************
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SwapArrays { | |
public static void main(String[] args) { | |
int[] arr = {10, 20, 30, 40, 50}; | |
System.out.println("Original array: "+ Arrays.toString(arr)); | |
swap(arr, 0, 4); | |
System.out.println("Swapped Array: "+ Arrays.toString(arr)); | |
reverseArray(arr); | |
} | |
private static void swap(int[] arr, int index1, int index2) { | |
int temp = arr[index1]; | |
arr[index1] = arr[index2]; | |
arr[index2] = temp; | |
} | |
} | |
Output: | |
Original array: [10, 20, 30, 40, 50] | |
Swapped Array: [50, 20, 30, 40, 10] |
No comments:
Post a Comment