simple java program to swap two numbers without using a temp variable
The simplest method to swap two variables is to introduce a third or temp variable. This isn't the most ideal scenario as it takes up another space in your computers memory. This program takes two numbers (A and B). It adds the values of A and B and saves them in A. B is then substracted from A and stored in B. Finaly B is substracted from A and stored in A
a = 3; b = 5;
a = a + b;
a = 8; b = 3;
b = a - b;
a = 8 b = 3
a = a - b;
a = 5; b = 3;