CMPS 144L
Lab Activity: Loop Invariant for Multiply

Complete the productOf() method in the Java class Multiply. Its purpose is to compute the product of its two integer arguments k and m, the first of which is assumed to be nonnegative. To complete the method, all that is needed is for the right-hand sides of three assignment statements to be filled in correctly (to replace the ??'s).

To ensure that the code you supply conforms to the loop invariant, which is result == i*m, there are assert statements to verify that the invariant is true immediately before and after each loop iteration. (If, when an assert statement is executed, the condition specified in the statement evaluates to false, an exception is thrown.)

By default, assertions are disabled in Java, which means that they have no effect. To enable them, follow these instructions.

To test your work, the class includes a main() method that expects to receive two arguments describing the integers to be multiplied. If you don't know how to supply an application program with "command line" arguments (or what jGrasp refers to as "run" arguments), ask your GTA. Or read this.