0

Swap variables without introducing third variable

Int a=5; Int b= 6; How will you swap the variables ?(a=6, b=5)

9th Jan 2020, 11:31 AM
LearnerLipi
LearnerLipi - avatar
7 Respuestas
+ 9
a=a*b b=a/b a=a/b
11th Jan 2020, 3:44 AM
Saroj Patel
Saroj Patel - avatar
+ 5
Use this trick.. If u want to swap a and b., a=a+b; b=a-b; a=a-b; You will get it
9th Jan 2020, 1:35 PM
Geethika Sewwandi
+ 4
It's simple addition and subtraction, just play with those numbers and you will end up getting the answer.
9th Jan 2020, 12:07 PM
Avinesh
Avinesh - avatar
9th Jan 2020, 6:04 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
I'm sure you'll find some examples online, have you searched on google ?
9th Jan 2020, 11:32 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Strings are immutable and you can update the same variable with new values but remember every time you do that, you will create a new object.
9th Jan 2020, 2:41 PM
Avinesh
Avinesh - avatar
+ 1
Avinesh : What when it's string?
9th Jan 2020, 1:36 PM
LearnerLipi
LearnerLipi - avatar