IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Write a Swap method in Java

3 posters

Go down

Java Write a Swap method in Java

Post by BIT0102-Mohaimin 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.
BIT0102-Mohaimin
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

Back to top Go down

Java Re: Write a Swap method in Java

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

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

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Java Re: Write a Swap method in Java

Post by BIT0102-Mohaimin 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
BIT0102-Mohaimin
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

Back to top Go down

Java Re: Write a Swap method in Java

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

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

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Java Re: Write a Swap method in Java

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

Sounds interesting Neutral I think I should give a try too.
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Java Re: Write a Swap method in Java

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

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

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.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

Back to top

- Similar topics

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