+ 1
Hi every body!!! this is a logic Quiz!!
lets suppose that you are working in a company and they want you to make a two numbers sum program and they will give you 5000$đ±đ±đ if you did it. but your laptop don't have the( +,-) signs ,you can't to use sum methods or fuctions and there is no internet connectionđđđ«. so you have to write a smart code to sum the two numbersâșđđ.
3 Respostas
+ 2
Woops I can't read
Let's try again
public int sum(int a, int b){
if (b == 0){
return a;
} else {
return sum( a ^ b, ( a & b ) << 1);
}
Using some bit arithmetic and recursion, this adding function handles the case where 2 intersecting 1 bits will cause a left shift of the bit to the next highest binary
+ 1
Here's a solution in Java using streams;
This method returns any 2 integers passed to it, given java.util.stream.* is imported.
public int sum(int a, int b){
int addList = {a, b};
int total = IntStream.of(addList).add();
return total;
}
+ 1
Sorry bro but .add() is not accepted