Question 0-1

Suppose a user executes the following run() method and types the numbers 5 and 22.

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  5
b 22
m  0  5 10 15
n 22 17 12  7
The method will print ``8.''

Back to 9:40 Quiz 0