I would like to know how I could multiply negative numbers in java without using the * operator.
int finalValue= 0;
public int product(int leftFactor, int rightFactor) {
for(int i=1; i<=rightFactor; i++){
finalValue += leftFactor;
}
return finalValue;
}
In this way I can multiply the numbers but only if both are positive but in case one of the two values is negative or both, the loop does not work.
Playing with the signs of the operators, you can do a normal multiplication and depending on the sign of each operator, you give one sign or another to the result.