aspose file tools
The moose likes Java in General and the fly likes swapping the data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "swapping the data" Watch "swapping the data" New topic

swapping the data


Joined: Oct 04, 2003
Posts: 7
I have some values in array like
int a[]={1,2,3,4,5,6,7,8,.....};
i have to swap the elements of array to get the result
can anyone help me out.
Thanks in advance
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
What specific problems are you having ?
I'm not going to do your homework for you
John Brookes

Joined: Feb 26, 2004
Posts: 29
If you just have to swap each pair within the array, you'd need a dummy variable and a loop.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
To illustrate that:

There are some cool mathematical tricks to swap two integers without using a temp variable, but this is the kindest solution to future readers of your code.
Hope that helped. And hope I haven't just stepped in and done somebody's homework.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: swapping the data