Link Details

Link 930523 thumbnail
User 884233 avatar

By screener
Published: Feb 26 2013 / 08:36

Swapping two number without using temp variable is a classical programming exercise, appears in various Java Interviews. Couple of ways to solve it.
  • 9
  • 3
  • 1469
  • 1183


Add your comment
User 111696 avatar

bloid replied ago:

-1 votes Vote down Vote up Reply

Whilst reasonably interesting from an academic point of view, the addition and multiplication methods will fail if anything overflows. The multiplication method will fail if one of the variables is zero. Also all of the methods are harder to read and will probably be slower than using a temp variable and a decent compiler...

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java