In this Tutorial we are going to swap two variables. Here swapping means, inter changing the values of two variables . For Example . int a =10 , int b =20 ; after swapping a , b values will be 20 and 10 respectively . see the below example.

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

Leave a Reply

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