Write a Swap method in Java

View previous topic View next topic Go down

Java Write a Swap method in Java

Post by BIT0102-Mohaimin on Sat Feb 12, 2011 8:32 pm

You may have seen/written a code like the one bellow in C to swap two values.
Code:

void swap(int* x, int *y)
{
   int temp = *x;
   *x = *y;
   *y = temp;
}
I assume that you understand why the pointers are necessary.

Can you write something like this in Java. I tried several time and finally I came to a conclusion few days ago.
Remember, Java does not allow pointers.
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Java Re: Write a Swap method in Java

Post by BIT0112-Rokon on Sat Feb 12, 2011 8:47 pm

I think I can write this program but you don't want me to do it, right.

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Java Re: Write a Swap method in Java

Post by BIT0102-Mohaimin on Sat Feb 12, 2011 8:58 pm

BIT0112-Rokon wrote:I think I can write this program but you don't want me to do it, right.
Right Very Happy
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Java Re: Write a Swap method in Java

Post by BIT0112-Rokon on Sat Feb 12, 2011 9:12 pm

Sorry yaar,
Without array or object, you cant do it in within a method.

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Java Re: Write a Swap method in Java

Post by BIT0122-Amit on Sat Feb 12, 2011 9:27 pm

Sounds interesting Neutral I think I should give a try too.

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Java Re: Write a Swap method in Java

Post by BIT0122-Amit on Sat Feb 12, 2011 9:33 pm

Hmm, a few lines on paper, and I guess I have to agree with Rokon.

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Java Re: Write a Swap method in Java

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum