How to Add Two Integers Without Arithmetic Operator in Java
The challenge
Given two integers a, b, find The sum of them, BUT You are not allowed to use the operators + and –
Notes
- The numbers (a,b) may be positive , negative values or zeros .
- Returning value will be an integer .
- Java: the following methods are prohibited: addExact, average, collect, decrement, increment, nextAfter, nextDown, nextUp, reduce, subtractExact, sum, summing .
The following classes are prohibited: BigDecimal and BigInteger .
Examples
The solution in Java code
Option 1:
Option 2:
Option 3:
Test cases to validate our solution
|
|