8:00 Quiz 0

One-page version suitable for printing.

Statistics:

mean     23.400 (351.000/15)
stddev   5.017
median   24.000
midrange 19.000-28.250

# avg
1 9.33 / 10
2 7.60 / 10
3 6.47 / 10

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

Question 0-2

Say we've defined the following method.

public static int f(int n) {
    IO.print(n);
    return 1 + n;
}
Suppose our program executes the line
IO.println(3 + f(2 + f(1)));
What is printed in executing this line?

Solution

Question 0-3

Fill in run() so that, when executed, the method will compute the factorial of a number the user types. A user executing the method should see the following, for example. (Boldface indicates what the user types.)

Number: 4
24
Recall that n factorial is the product of the integers up to n; for example, the factorial of 4 is 1*2*3*4 = 24.
import csbsju.cs160.*;

public class FindFactorial {
    public static void run() {



    }
}

Solution