0

Hello everybody! How would you swap the value of two variables without use any other variable in Java?

For example a=10 and b=5. The result should be a=5 and b=10

22nd Sep 2020, 4:48 PM
Omar Medrano Sarabia
Omar Medrano Sarabia - avatar
1 Answer
0
Sorry, I was not trying to test you. It's just that I saw the question in a challenge here in SoloLearn and I want to know the right answer. Anyway, here is the way to do it: a = a + b; b = a - b; a = a - b;
22nd Sep 2020, 5:11 PM
Omar Medrano Sarabia
Omar Medrano Sarabia - avatar