Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

swapping the elements in an array at the given index

 
Ambreen Khanam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic