In this Tutorial we are going to swap two variables without using temporary variable . Here swapping means, inter changing the value of two variables


public class SwapWithoutTemp{
 public static void main(String[] args) {
      int a= 10 , b =20;
      a = a+b;
      b = a-b;
      a = a-b;
      System.out.println("After Swapping  a = "+a+"  :  b = "+b);
   }
}


Leave a Reply

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