We need to handle cases where both inputs are positive, both are negative, or one is positive and the other is negative:
public static int mult(int a, int b) {
int product = 0;
boolean positiveProduct = !(a >= 0 ^ b >= 0);
a = Math.abs(a);
b = Math.abs(b);
int min = Math.min(a, b);
int max = Math.max(a, b);
while (min > 0) {
if (positiveProduct)
product += max;
else
product -= max;
min--;
}
return product;
}