In this article, you will learn how to write a java program to add two numbers without using the + or ++ operators. It sounds interesting enough for novices to think beyond their abilities, but it is very easy for math enthusiasts. Before that in the last tutorial we explained how to add two numbers in java and show the problems that occur. And also showed the example to read user input using the scanner.
2. Java program for adding without operator +
Let’s move on to our topic today. How can you solve this problem? As stated before, if you have mastered the basic concepts of math, then you would have guessed the solution. The answer will be very, very simple.
Hint: in the problem statement, it is mentioned that must not use the + operator, But you can still use the remaining operators.
Before seeing the solution, first put your thoughts on paper and see the original answer.
Here used a simple formula result = a – (- b) which is equivalent to “A + b”.
In this tutorial you have learned that we can always add two numbers even if you don’t use the + operator.
In the next tutorial we will discuss and understand how to add two numbers without using operator.