This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design 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: 44031
    
  33
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.
 
Have you checked out Aspose?
 
subject: swapping the elements in an array at the given index
 
It's not a secret anymore!