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
Why we use protected in java?
what invokes a threads run() method? : Java thread
In the below example, how many string objects are created?
How to sort list of list in java?
How is Object Oriented Programming different from Procedure Oriented Programming?
What is abstract class? Explain
How do you remove an object from an arraylist in java?
What is instanceof keyword?
What is boolean strategy?
define polymorphism in java
What is string variable?
What is static keyword in java?
What is an error in java?
Where is java located?
Can java inner class be static?