Bitwise recursive addition of two integers | Java program to do recursive addition of two integers ; If bitwise & is 0 , then there is not going to be any carry . Hence result of XOR is addition . ; Driver code
import java . io . * ; class GFG { static int add ( int x , int y ) { int keep = ( x & y ) << 1 ; int res = x ^ y ; if ( keep == 0 ) return res ; return add ( keep , res ) ; } public static void main ( String [ ] args ) { System . out . println ( add ( 15 , 38 ) ) ; } }