Say x & y are the integer variables. The challenge is to swap them without using a temporary variable. The solution is as simple as the problem itself: x = x + y; y = x - y; x = x - y; Update 1: Jack and Alexey pointed out a typo in my solution which has since been corrected. Please see their comments below. The simplicity of the solution appeals to me. It clearly demonstrates the meaning of assignment operator ( "=" ). What if they are Strings? Note: You can use String methods in Java API.
Older News
S M T W T F S
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
Copyright© 2011 The Gaea Times