How to add two numbers with out using Arithmetic , union
operators in java....?
But we can use bitwise operators... but how...?
Answer Posted / midhula
public int addtwo(int a,int b)
{
if(b==0)
return a;
int sum = a ^ b; // ^ will be 1 if both operands are
//different otherwise 0.
int carry = (a & b) <<1; //& will be 1 if both operands are
//1 otherwise 0
return addtwo(sum,carry);
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is append in java?
What is type safety in java?
How to change the priority of thread or how to set priority of thread?
What is the difference between a factory and abstract factory pattern?
What is var keyword ?
What does this mean java?
Which of the classes will have more memory allocated?
Lowest Common ancestor in a Binary Search Tree and Binary Tree.
What do you mean by local variable and instance variable?
Is string an object?
What is int lol?
Where import statement is used in a java program?
How do you use find and replace?
Is java free for businesses?
What is <> used for in java?