We can implement this by using recursive operation.
public static int multiply(int x, int y) {
if (y == 0)
return 0;
// if y is positive,Add x one by one
if (y > 0)
return (x + multiply(x, y - 1));
else
return -multiply(x, -y);
}
No comments:
Post a Comment