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 equals method in java?
How to calculate the length of a singly linked list in java?
What is the difference between a method and a function in alice?
What are thread groups?
What is formatted output?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?
What is meant by data hiding/encapsulation?
Can we declare a static variable inside a method?
State two differences between C and Java.
Can java list contain duplicates?
Can we override the overloaded method?
Explain the features of java?
What is function overriding and overloading in java?
Can we define constructor in inner class?
What is the default access specifier for variables and methods of a class?