While Loop Simulation
Category: Simulation
Author: Marty Stepp
Book Chapter: 5.1
Problem: While Loop Simulation
For each call below to the following method, write the value that is returned:
public static int whileMystery(int a) {
int b = 1;
int c = 0;
while (b <= a) {
if (b % 2 == 0) {
c++;
}
b = b * 10;
c++;
}
return c + 1;
}
1) whileMystery(2);
2) whileMystery(84)
3) whileMystery(4097)
4) whileMystery(388)
5) whileMystery(23980)