Java program to swap two numbers without using temp variable

Java program to swap two numbers without using temp variable

class Swap
{
public static void main(String…s)
{
int a,b;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);

System.out.println(“nBefore Swap:n”+”a=”+a+”tb=”+b);

a=a+b;
b=a-b;
a=a-b;

System.out.println(“nAfter Swap:n”+”a=”+a+”tb=”+b);
}
}

" data-link="https://twitter.com/intent/tweet?text=Java+program+to+swap+two+numbers+without+using+temp+variable&url=https%3A%2F%2Fwww.thecrazyprogrammer.com%2F2013%2F08%2Fjava-program-to-swap-two-numbers_23.html&via=">">Tweet
16 Shares

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.