While Loop Simulation
Category: Simulation
Author: Brett Wortzman
Book Chapter: 5.1
Problem: While Loop Simulation
For each call below to the following method write the output that is printed exactly as it would appear on the console:
public static void whileMystery(int a, int b, int c) {
int x = 0;
while (a >= c || b > c) {
a /= 2;
b -= c;
x++;
System.out.print("(" + a + ", " + b + ") ");
}
System.out.println("x = " + x);
}
1) whileMystery(16, 5, 1);
2) whileMystery(0, 1, 2);
3) whileMystery(30, 10, 5);
4) whileMystery(4, 15, 3);