Pages

Tuesday, June 16, 2015

Swap 2 Numbers with Exclusive Or

Here is a simple program to swap to numbers with Exclusive OR

 public class Swap {  
   public static void main(String args[])  
   {  
     int a=4;  
     int b=5;  
     a^=b;  
     b^=a;  
     a^=b;  
     System.out.println(a);  
     System.out.println(b);  
   }  
 }  

Output :

5
4

No comments:

Post a Comment