Java program to swap two numbers without using a 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);
}
}

Output

Java program to swap two numbers without using a temp variable

Leave a Comment

error: Alert: Content is protected!!