In this video we will learn to swap two numbers stored in two variables without taking help of a third variable.
In this video we are dealing we are dealing with a general formula which works perfectly well for both positive and negative values.
-----------------------------------------
Case 1: For two positive values
(Kindly watch the video)
-----------------------------------------
Case 2: For one positive and one negative value
If x = 10 and y = -20
x = x + y = 10 + (-20) = -10
y = x - y = (-10) - (-20) = 10
x = x - y = (-10) - 10 = -20
Now, x = -20 and y = 10
Value swapped.
---------------------------------------
Case 3: For two negative values
If x = -10 and y = -20
x = x + y = (-10) + (-20) = -30
y = x - y = (-30) - (-20) = -10
x = x - y = (-30) - (-10) = -20
Now, x = -20 and y = -10
Value swapped.
---------------------------------------
Thanks for reading and thanks for watching :-)
You can download the project code from my GitHub repository
https://github.com/yusufshakeel/Java-...
Watch video 01 Java | Swap two numbers without using third variable online, duration hours minute second in high quality that is uploaded to the channel Yusuf Shakeel 24 May 2014. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 18,208 times and liked it 127 visitors.