5.19 Swapping of 2 Numbers in Easy way

  Рет қаралды 73,702

Telusko

Telusko

8 жыл бұрын

In this video we will see how to swap 2 numbers in easiest way. We use a new formula: b = a+b-(a=b) to swap 2 numbers. we first solve round brackets then the rest.
Example: a=5 b= 6
b= 5+6-(a=6)
so, b= 11-6 = 5
therefore. a=6 and b = 5
Check out our website: www.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearnings
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : / @navinreddy
Telusko Hindi :
/ @teluskohindi
Subscribe to the channel and learn Programming in easy way.
Java Tutorial for Beginners: goo.gl/p10QfB
C Tutorial Playlist : goo.gl/8v92pu
Android Tutorial for Beginners Playlist : goo.gl/MzlIUJ
XML Tutorial : goo.gl/Eo79do
Design Patterns in Java : goo.gl/Kd2MWE
Socket Programming in Java : goo.gl/jlMEbg
Spring MVC Tutorial : goo.gl/9ubbG2
OpenShift Tutorial for Beginners : goo.gl/s58BQH
Spring Framework with Maven : goo.gl/MaEluO
Sql Tutorial for Beginners : goo.gl/x3PrTg
String Handling in Java : goo.gl/zUdPwa
Array in Java : goo.gl/uXTaUy
Java Servlet : goo.gl/R5nHp8
Exception Handling in Java : goo.gl/N4NbAW

Пікірлер: 35
@smokey750
@smokey750 6 жыл бұрын
Another trick you can do is a=a^b^(b=a) or a^=b^(b=a) if you desire that notation. This form also helps understand why the xor trick works when swapping bits since a gets set to a xor b xor a where the two a's in the xor will cancel out leaving the a = b, and at the end we directly set b = a as the last preformed operation requiring b.
@shreyaskamarthi
@shreyaskamarthi 6 жыл бұрын
Best video I have ever seen on KZbin. So easy way. Just one line solution. Great man.
@SmartProgramming
@SmartProgramming 6 жыл бұрын
nice explanation sir, way of explanation is so nice, keep it up 👍👍
@nilesh122n
@nilesh122n 8 жыл бұрын
perfect,it is new logic
@pitaji_badewale
@pitaji_badewale 3 жыл бұрын
but in expression b=a+b-(a=b), why the value of first a is still 5 while the second one already assigned to 6??
@mollasakil694
@mollasakil694 2 жыл бұрын
Best technique...I never thought about itt
@soniasu2744
@soniasu2744 5 жыл бұрын
great tutor
@shuvshaw9594
@shuvshaw9594 4 жыл бұрын
very helpful
@sayanmukherjee8563
@sayanmukherjee8563 6 жыл бұрын
Sir how in one line the left a holds the value 5 and the right a holds the value 6.I mean to say when (a=b) is written the left a won't change its value?
@moorgoolean
@moorgoolean 5 жыл бұрын
Suscribed!
@theAnalyticGuy
@theAnalyticGuy 6 жыл бұрын
This wont work if values of A and B are near Integer.MAX_VALUE. There will be overflow because we are adding.
@mayanksingla492
@mayanksingla492 6 жыл бұрын
if brackets will be resolve first then 1st "a" should also have 6 value but it has 5, how?
@snehalgavate3182
@snehalgavate3182 6 жыл бұрын
This works too ☺️--->
@archanamharish568
@archanamharish568 7 жыл бұрын
cant we just swap while printing a and b like this??system.out.print(b+" "+a);
@nidhisharma-wf3lv
@nidhisharma-wf3lv 2 жыл бұрын
For A=5, B=10 short formula is not working
@sarveshkhire415
@sarveshkhire415 6 жыл бұрын
We can also do this to swap
@francescopiazza4882
@francescopiazza4882 4 жыл бұрын
gulp!
@tummalaramakrishna5725
@tummalaramakrishna5725 8 жыл бұрын
we can also swapping using new varble
@thespiritualjourney369
@thespiritualjourney369 3 жыл бұрын
previous way was a lot easy than this. This is not at all easy. Its more complicated.
@sarthakhaldar9107
@sarthakhaldar9107 3 жыл бұрын
200 IQ
Java Tutorial | Array Theory
6:28
Telusko
Рет қаралды 171 М.
14.11 HashMap and HashTable in Java
8:44
Telusko
Рет қаралды 670 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
00:56
صدام العزي
Рет қаралды 37 МЛН
Самое Романтичное Видео ❤️
00:16
Глеб Рандалайнен
Рет қаралды 6 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 10 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН
Functional Interface | Lambda Expression in Java
13:56
Telusko
Рет қаралды 139 М.
4.5 Post and Pre Increment in Java
7:06
Telusko
Рет қаралды 207 М.
Valorant Tips And Tricks Sent By You - Part 63
9:35
MrLowlander
Рет қаралды 38 М.
5.15 Perfect Number in Java
5:48
Telusko
Рет қаралды 144 М.
#42 This keyword in Java
9:45
Telusko
Рет қаралды 112 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
00:56
صدام العزي
Рет қаралды 37 МЛН