Hi,
Can u add numbers without using arithmetic operators in java.We can add using bitwise operators.But i m not able to get the ans.

Solve:

a+b=c;
Prove 2+2=4 without using arithmetic opreations.

8
Contributors
12
Replies
13
Views
9 Years
Discussion Span
Last Post by stultuske
Featured Replies
• 1

And I want a billion dollars :-/

What have you done on this problem? Show us some effort and maybe you will receive help. Also, try google.

I want to add two numbers for example say 2+3=5 without the arithmetic operator '+'.

And I want a billion dollars :-/

Excellent response

One way that came to mind is use 2 for-loops

010
AND
010
is
100

We can multiply/divide by 2 succesive using bitwise operators .

``````byte a = 4;
byte b = (byte) (a >> 1);
byte c = (byte) (a >> 2);
byte d = (byte) (a << 1);

System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);``````

May be You are looking to The Vedas (Sanskrit वेद, véda, "knowledge") arithmetic .The product of the sum - Gunitasamuchyah.
(or Trachtenbergs system to speed multiply in memory).
quuba

I m still can't get the answer from u guys.....

Let me explain more in detail:

public static void main(String args[])
{
int a=2,b=2,c;
c=a+b;
System.out.println("C="+c);
}
}

This what we normally done using arith operator '+'.
I want the answer c=4 without using '+' or any arith operator.
Pls suggest ur ideas through the example.. i m a beginner in java so i can clearly understand... Hoping for u r answers......

`c=a+b;` - here is arithmetic operator . `System.out.println("C="+c);` - here is overloaded operator + .
Here this mean CONCATENATION of two String-s.
You can asked: c is not a String type. Yes it is true, but c is casting to String automatically before join.
In Your case You can write:

``````System.out.print("C=");
System.out.println(""+c);// "" (an empty String) can cast integer to String``````

How to eliminate sign + :

``````System.out.print("C=");
System.out.println(c);// "" automatic cast int to String``````

Remark: Sign + in arithmetic has two menings:
1. before a single number indicate, positive number
2. between two numbers , sum operation

Try write: `System.out.println(c++);` or `System.out.println(++c);` try explain difference
quuba

Use XOR .

@thariqrasheed

K guys.... I think u are not well versed in Java than me... Can't even find a solution to the answer for adding...

k... Cool

just write the pgm for

2+2=4 without using '+' operation using java.