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
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
Does collectionutils isempty check for null?
Write a program to find the greatest of three numbers in java?
What is assembly language?
How do you define a set in java?
Can a constructor have different name than a class name in java?
What is the escape character in java?
What is identifier with example?
What is meant by 'Class access modifiers'?
What is the maximum size of array in java?
What are the benefits of immutable objects?
How will you calculate the depth of a binary tree if the tree contains 15 nodes?
What is module in project?
Can we have try without catch block?
What are locale settings?