can we add two numbers without using arthematic operators?
if possible how?
Answer Posted / mohan
public static int addIterative(int a, int b){
while (b != 0){
int carry = (a & b) ; //CARRY is AND of two bits
a = a ^b; //SUM of two bits is A XOR B
b = carry << 1; //shifts carry to 1 bit to calculate sum
}
return a;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what is the significance of listiterator in java?
What is string immutability?
Define how objects are stored in java?
What is sortedmap in java?
What are the advantages and disadvantages of object cloning?
What happens if an exception is not handled in a program?
How many types of methods are there?
Why are pointers not secure?
State some situations where exceptions may arise in java?
What is exception propagation?
What is the difference between throw and throws in java?
Explain about procedural programming language or structured programming language and its features?
What is an object in java and how is it created?
When should we create our own custom exception classes?
How can we run a java program without making any object?