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);
}
}

Leave a Reply

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