While Loop Simulation
Category: Simulation
Author: Stuart Reges
Book Chapter: 5.1
Problem: While Loop Simulation
Consider the following method:
public static void mystery(int n) {
int x = 1;
int y = 1;
while (n > y) {
x++;
y = 10 * y + x;
}
System.out.println(x + " " + y);
}
For each call below, indicate what output is produced.
1) mystery(0);
2) mystery(7);
3) mystery(32);
4) mystery(256);