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 the 8 primitive data types in java?
Write a program to calculate factorial in java?
What is formatted output in java?
How to sort array in descending order in java?
What is considered an anti pattern?
Can you give few examples of final classes defined in java api?
Name some OOPS Concepts in Java?
Does sprintf allocate memory?
What is integer parseint?
Can a java program have 2 main methods?
what is the swingutilities.invokelater(runnable) method for? : Java thread
Is char * a string?
How do I start learning java?
What is oop principle in java?
What are the differences between abstract class and interface?