In our daily life we add some numbers and for this addition we use “+” sign. I have a one question, Can it be possible without using plus sign we add numbers? the answer is Yes! we can add two numbers without using the plus (“+”) sign.

In the below program we use two different methods for addition of two numbers. First method add() in which we add two numbers a and b without using +. And second method is recursive method i.e. recursiveAdd().

Both methods are produce same output. Instead of using + operator we use & , ^, << this operators for addition. The & operator are bitwise & which is used in java for adding bitwise numbers in java. Bitwise numbers is binary numbers stored in a integer form.

Let’s see how to write addition program using &, ^ and << operators.

``````public class AddWithoutPlus
{
public static int add(int a, int b)
{
if (b > a)
{
int temp = b;
b = a;
a = temp;
}
int carry = 0;
while (b != 0)
{
carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a;
}
public static int recursiveAdd(int a,int b)
{
if (b == 0)
return a;
else
return recursiveAdd(a ^ b, (a & b) <<1);
}
public static void main(String[] args)
{
int a = 12;
int b = 34;
``````46