5.18 Swapping of Two Numbers in Java in 3 Different ways

  Рет қаралды 156,907

Telusko

Telusko

Күн бұрын

Swapping of Two numbers with 3 different Logics
1. Using Temp
2. Without using Temp variable
3. XOR
In this video we will see how to interchange the values of 2 variable. That means if there are 2 variables a = 5 & b = 4 after swapping the value of a = 4 & 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

Пікірлер: 39
@SmartProgramming
@SmartProgramming 6 жыл бұрын
nice one sir, third way is new for us, thanks and keep it up 👍👍
@arghadeep6363
@arghadeep6363 6 жыл бұрын
Thanks for the programs
@srikanthchilamkuri8069
@srikanthchilamkuri8069 5 жыл бұрын
3rd method is super sir..
@milind006
@milind006 4 жыл бұрын
Unless you’re using a specialised compiler which compiles for a specific system which has some very critical memory limitations, an Internet declaration will simply assign 32 bits (4 bytes) for an int. So whether you need 3 or 4 bits is immaterial and the full 32 bits will be used for an integer anyway. Memory isn’t assigned by bits, but by words. So even if a data type requires only 1 byte, if the default word size of an OS is 4 bytes, 4 bytes will be used even for such a data type because the performance benefits of using a fixed word size outweigh the memory benefits of saving a bit. Furthermore, it is always useful to have code which is clear to understand when you consider maintenance, and from the perspective, the first method is the easiest to understand, and would be preferred in a professional setting
@shuvshaw9594
@shuvshaw9594 4 жыл бұрын
very helpful
@uss3ewa
@uss3ewa Жыл бұрын
thx for xor search for this around 15 min
@user-qg9nd5jv8s
@user-qg9nd5jv8s 2 жыл бұрын
Bravo!
@iVodkaBeerMaikMB
@iVodkaBeerMaikMB 5 жыл бұрын
thanx man
@muftinowsheen3597
@muftinowsheen3597 5 жыл бұрын
Sir how to swap 3 numbers in java?
@pavuk7086
@pavuk7086 4 жыл бұрын
Спасибо мужик!!!
@tonpenarayana7507
@tonpenarayana7507 5 жыл бұрын
awesome
@kalyanroy6687
@kalyanroy6687 8 жыл бұрын
Its wrong to ask this here,but still i wanna ask u,, Can you please make tutorials on Data Structures and Algorithms?
@mohammedviso2269
@mohammedviso2269 9 жыл бұрын
Thank you a lot.....
@miguelconstantino-guzman7957
@miguelconstantino-guzman7957 2 жыл бұрын
Does anyone know how to swap two numbers given a Number class? It is an object that the reading did not cover. I am given a static swap method with two Number objects as parameters, no return type, and two Number objects in the main method, each initialized with two user-int inputs. The swap method in main is: swap(num1, num2) and passed to the static method swap(Number num1, Number num2) { ... }. Also: the Number class contains a setter and getter method with a constructor, public Number(int n) { num = n; } where num is a private member field.
@meenakshitomar2943
@meenakshitomar2943 8 жыл бұрын
why are we passing (string[] args) as a parameter to main func? can u please answer?
@meenakshitomar2943
@meenakshitomar2943 8 жыл бұрын
Thankyou... sir
@ito6787
@ito6787 Жыл бұрын
My four key is swapped with the numbers 2 and 3 being pressed once very quickly, can someone comment a step by step on how to fix it?
@sandeepreddy7716
@sandeepreddy7716 7 жыл бұрын
how is possible when four byte = three bytes example a=9 and b=4 by using xor
@Gtvteluguindia
@Gtvteluguindia 7 жыл бұрын
possible
@023PrashantSharma
@023PrashantSharma 6 жыл бұрын
let a=9=1001 b=4=100 we can also write.. 1001 0100 ```````` a=a^b//1000^0100==1101=13 b=a^b//1101^0100==1001=9 a=a^b//1101^1001==0100=4 a=4 b=9 so easy if u have knowledge of boolean algebra..
@manoharreddy4988
@manoharreddy4988 4 жыл бұрын
Why can't we just assign the number value alphabets in system.out.println
@xReema
@xReema 5 жыл бұрын
❤️❤️❤️❤️🙏🏻🙏🏻🙏🏻🙏🏻
@hemalathahema8976
@hemalathahema8976 5 жыл бұрын
sir there is another way which is a=a*b; b= a/b; a= a/b.
@duggirambabu7792
@duggirambabu7792 2 жыл бұрын
It is applicable when a≠0 and b≠0.
@Thegamer-yp7qq
@Thegamer-yp7qq 8 жыл бұрын
in OR 1 1 = 1 not 0 ?right?
@suseelasusi2879
@suseelasusi2879 4 жыл бұрын
It's XOR operation
@duggirambabu7792
@duggirambabu7792 2 жыл бұрын
0 OR 0 = 0 0 XOR 0 = 0 0 OR 1 = 0 0 XOR 1 = 1 1 OR 0 = 0 1 XOR 0 = 1 1 OR 1 = 1 1 XOR 1 = 0
@Karansaini54777
@Karansaini54777 7 жыл бұрын
my friend send me mobile number but i cannot see these number hiding number in xxxxxxxx please give me solution to see
@shuvshaw9594
@shuvshaw9594 4 жыл бұрын
// using extra variables int x=100,y=200,extra; extra=x; x=y; y=extra; System.out.printf("X is now %d Y is now %d ",x,y);
@shuvshaw9594
@shuvshaw9594 4 жыл бұрын
//^ stands for XOR operation int x=100,y=200; x=x^y; y=x^y; x=x^y; System.out.printf("X=%d and Y=%d",x,y);
@jatingandhi4286
@jatingandhi4286 6 жыл бұрын
One more easy way a=a*b b=a/b a=a/b
@milind006
@milind006 4 жыл бұрын
It fails if b is 0. Also, doesn’t translate well to char, or even float types especially if you want the program to be portable across OS
@Juliodonadello
@Juliodonadello 3 жыл бұрын
doesn`t work with 0 and should be: a=a*b b=a/b a=a/b
@prashanthkuntrapakam
@prashanthkuntrapakam 8 жыл бұрын
reddy rules
@shuvshaw9594
@shuvshaw9594 4 жыл бұрын
// using +,- operation int x=100,y=200; y=x+y; x=y-x; y=y-x; System.out.printf("X is now %d Y is now %d ",x,y);
@milind006
@milind006 4 жыл бұрын
You’re mixing Java and C here.
@shuvshaw9594
@shuvshaw9594 4 жыл бұрын
@@milind006 Kindly tell how.
@milind006
@milind006 4 жыл бұрын
​@@shuvshaw9594 You know what, turns out I was unaware of the existence of the System.out.printf method for printing to the standard output. There is nothing wrong with your code snippet. I learned something new :)
5.19 Swapping of 2 Numbers in Easy way
3:20
Telusko
Рет қаралды 73 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 511 М.
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 67 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 39 МЛН
the TRUTH about C++ (is it worth your time?)
3:17
Low Level Learning
Рет қаралды 662 М.
Multithreading in Java Explained in 10 Minutes
10:01
Coding with John
Рет қаралды 903 М.
5.10 Loop pattern Logic in Java Tutorial
11:08
Telusko
Рет қаралды 170 М.
Java Program #30 - Find LCM of Two Numbers in Java
7:46
Programming For Beginners
Рет қаралды 12 М.
6.10 Enhance For Loop in Java | For Each Loop
5:16
Telusko
Рет қаралды 107 М.
Hash Tables and Hash Functions
13:56
Computer Science
Рет қаралды 1,5 МЛН
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН