Swap three variables without using temporary variable | Java program to swap three variables without using temporary variable . ; Assign c ' s ▁ value ▁ to ▁ a , ▁ a ' s value to b and b 's value to c. ; Store XOR of all in a ; After this , b has value of a ; After this , c has value of b ; After this , a has value of c ; Driver Code ; Calling Function
class GFG { static int a , b , c ; static void swapThree ( ) { a = a ^ b ^ c ; b = a ^ b ^ c ; c = a ^ b ^ c ; a = a ^ b ^ c ; } public static void main ( String [ ] args ) { a = 10 ; b = 20 ; c = 30 ; System . out . println ( " Before ▁ swapping ▁ a ▁ = ▁ " + a + " , ▁ b ▁ = ▁ " + b + " , c ▁ = ▁ " + c ) ; swapThree ( ) ; System . out . println ( " After ▁ swapping ▁ a ▁ = ▁ " + a + " , ▁ b ▁ = ▁ " + b + " , ▁ c ▁ = ▁ " + c ) ; } }