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-...
Смотрите видео 01 Java | Swap two numbers without using third variable онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Yusuf Shakeel 24 Май 2014. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 18,208 раз и оно понравилось 127 посетителям.