How to write a program in java Addition of two numbers without using (+ plus) operator. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to write a program in java Addition of two numbers without using (+ plus) operator.

28th Feb 2018, 2:38 PM
chavan dipak dattatray
chavan dipak dattatray - avatar
2 Answers
+ 2
https://code.sololearn.com/c3NFgbWCU5T8/?ref=app This is a program I wrote in Python. You could use the same method to add without + in Java.. My solution (maybe not the desired solution, but the one I can up with) .. My solution was to for loop thru X and Y number of times, adding a number to an array each time.. the sum of X + Y becomes the length of the array. For Example.. - X=5 Y=3 EmptyArray=[] for(int i=0; i<X; i++){ add I to EmptyArray } for(int i=0; i<Y; i++){ add I to EmptyArray } Sum = length(EmptyArray);
28th Feb 2018, 3:27 PM
LordHill
LordHill - avatar
0
//this is probably cheating: public class Program { public static void main(String[] args) { System.out.print(5-(-5));//5+5 //outputs 10 } }
3rd Mar 2018, 9:49 AM
Danilo
Danilo - avatar