my dog learned polymorphism*
The moose likes Java in General and the fly likes swapping the elements in an array at the given index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "swapping the elements in an array at the given index" Watch "swapping the elements in an array at the given index" New topic
Author

swapping the elements in an array at the given index

Ambreen Khanam
Greenhorn

Joined: Apr 18, 2013
Posts: 4
Please provide me the best optimised solution for the below problem.

Say there is an array Array[1,2,3,4,5,6,7,8]. The elements needs to be swapped from index 0 to 4. The output should be somethin like this.

5,4,3,2,1,6,7,8
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
Welcome to the Ranch
We do not simply provide such solutions. I suggest you start with a method two swap two elements, in a utility classThen you use that method to swap however many elements you need to swap.
 
Consider Paul's rocket mass heater.
 
subject: swapping the elements in an array at the given index
 
Similar Threads
Multi column list box
How do you add objects to arrays?
how to solve arrayindexoutofbound exception
Array elements
[Solved] bubbleSorting + binary searching from methods .