code to swap two numbers in java????!!!!!!!!!!

  • 13 years ago

    hi all,Big Smile 

    code to swap two numbers in java without using temp variable.

     

    please reply. 

  • 13 years ago

    logic

    a=10

    b=20

    a= a+b // now a wii have 30 valve

    b= a-b  // now a will have 30-20 = 10 value

    a= a-b  // which is 30-10 =20

    now a=20

    and b= 10

    and the values r swaped 

     

     

     

     

     

    .

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan