Consider the loop below, intended to compute
ans as the product of a and b:
// return the product of a and b, which must be supplied as positive integers.
public static int mpy(int a, int b) {
int ans = 0,
i = b;
while (i != 0) {
i = i - 1;
ans = ans + ____________
}
return ans;
}
- What is the loop's termination condition?
- Fill in the blank in the above code so that the loop correctly
computes the desired product.
- In the method above, place a large dot (·) at each point where a loop invariant
should be true.