Swapping two variables in Java without using a third variable or an API -
this question has answer here:
i went interview , asked write code swap values of 2 variables without using third variable or api.
i not work out how this, can me on this?
for example have 2 variable a=10 , b=20 output should b=10 , a=20.
tricky not hard figure out:
a = 10 b = 20 = + b; //a = 30, b = 20 b = - b; //a = 30, b = 10 = - b; //a = 20, b = 10
Comments
Post a Comment