Itz done by using XOR Operator...
int a = 2, b = 3;
a ^= b;
b ^= a;
a ^= b;
System.out.println("A Value : " + a + " : " + "B Value : " +b);
a^=b ---> 010(2) ^ 011(3) ---> 001(1) ---> a = 1
b^=a ---> 011(3) ^ 001(1) ---> 010(2) ---> b = 2
a^=b ---> 001(1) ^ 010(2) ---> 011(3) ---> a = 3
Try this out......
No comments:
Post a Comment