How to swap two numbers without using a temporary variable ? | Java program to swap two numbers ; Function to swap the numbers . ; same as a = a + b ; same as b = a - b ; same as a = a - b ; Driver Code ; Function Call
import java . io . * ; class GFG { public static void swap ( int a , int b ) { a = ( a & b ) + ( a b ) ; b = a + ( ~ b ) + 1 ; a = a + ( ~ b ) + 1 ; System . out . print ( " After ▁ swapping : ▁ a ▁ = ▁ " + a + " , ▁ b ▁ = ▁ " + b ) ; } public static void main ( String [ ] args ) { int a = 5 , b = 10 ; swap ( a , b ) ; } }