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 are namespaces in java?
Can we override compareto method?
How do you declare an array in java?
What is the difference between normal report & matrix report?
What is arguments in java?
Explain java coding standards for methods?
What is a finally block? Is there a case when finally will not execute?
How many threads can java run?
Explain the importance of finally over return statement?
What is empty string literal in java?
What is ascii code?
What 5 doubled?
What is super in java?
What is queue in java?
How to find the largest value from the given array.