Question 0-1

Suppose a user executes the following run() method and types the numbers 4 and 17.

public static void run() {
    int a = IO.readInt();
    int b = IO.readInt();

    int m = 0;
    int n = b;
    while(m < n) {
        m += a;
        n -= a;
    }

    IO.println(m - n);
}
Show all the values taken on by the variables of the program.
a
b
m
n
What does the method print?

Solution

a  4
b 17
m  0  4  8 12
n 17 13  9  5
The method will print ``7.''

Back to 8:00 Quiz 0