This is a simple Java program that swaps two elements in an array based on user input. The user specifies two indices, and the elements at those indices are swapped.
This Java application performs the task of swapping two elements in an array. The user provides two indices, and the program exchanges the elements at those positions. It also ensures that the indices provided are within the bounds of the array to prevent errors.
- The program initializes an array with a few names.
- The user is prompted to enter two indices (positions) of the array.
- The program swaps the elements at those indices.
- The updated array is displayed after the swap.
- Initial array:
["Alex", "Max", "Charlie", "Bob", "Ada", "Jim"]
- User enters index
0
and3
. - After the swap:
["Bob", "Max", "Charlie", "Alex", "Ada", "Jim"]
- Clone the repository to your local machine:
git clone https://github.com/your-username/java-array-swapping.git