+ 1
How to write a program in java Addition of two numbers without using (+ plus) operator.
2 odpowiedzi
+ 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);
0
//this is probably cheating:
public class Program
{
public static void main(String[] args) {
System.out.print(5-(-5));//5+5
//outputs 10
}
}