Hi every body!!! this is a logic Quiz!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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☺😊😇.

23rd Jun 2017, 9:34 PM
Tarek Harba
Tarek Harba - avatar
3 Answers
+ 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
23rd Jun 2017, 10:31 PM
Jared
Jared - avatar
+ 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; }
23rd Jun 2017, 10:08 PM
Jared
Jared - avatar
+ 1
Sorry bro but .add() is not accepted
23rd Jun 2017, 10:16 PM
Tarek Harba
Tarek Harba - avatar