Friday, 30 October 2015

Interchange two value without third variable

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:

  1. Let a=10,b=20.
  2. Here a=a+b means a=10+20=30.
  3. Now value of a=30.
  4. Then b=a-b means b=30-20=10.
  5. Then a=a-b means a=30-10=20.
  6. So by this java interchanges the value.
  • Now print a & b.
  • Run the file and see what happens.

No comments:

Post a Comment