Link Details

Link 930523 thumbnail
User 884233 avatar

By screener
via javarevisited.blogspot.com.au
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
  • 1450
  • 1183

Comments

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.

Play Framework
Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Akka
  2. Design Patterns
  3. OO JS
  4. Cont. Delivery
  5. HTML5 Mobile
  1. Akka
  2. JUnit/EasyMock
  3. Java Performance
  4. REST
  5. Java