Link Details

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

Posted by screener  |   Feb 26 2013 / 08:36

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.

Comments

User 111696 avatar

bloid replied ago:

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...

Reply -1 votes

Recommended Links

Scala
Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Play
  3. Akka
  4. Debugging JavaScript
  5. Design Patterns
  1. Apache Hadoop
  2. REST
  3. Java
  4. Git
  5. Java Performance
Connect with DZone