Write a Program to interchange value of two variable without using third 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

5 6
Before Swap: a=5 b=6
After Swap:a=6 b=5
 

Explanation

In this Program, we have interchanged the value of variable without using third variable