Interchange two values without third variable
- Make new jFrame and add the components to frame like given in below figure.
- Open source code and declear three variables a,b,c as integer and also type the code of text fields.
- Type the code given below
- Now I will explain how java interchanges the value:
- Let a=10,b=20.
- Here a=a+b means a=10+20=30.
- Now value of a=30.
- Then b=a-b means b=30-20=10.
- Then a=a-b means a=30-10=20.
- So by this java interchanges the value.
- Now print a & b.
- Run the file and see what happens.