While Loop Simulation
Category: Simulation
Author: Jessica Miller
Book Chapter: 5.1
Problem: While Loop Simulation
For each call below to the following method, write the output that is produced, as it would appear on the console:
public static void whileMystery(int i, int j) {
int k = 0;
while (i < j && k < j) {
i = i + k;
j--;
k++;
System.out.print(i + ", ");
}
System.out.println(k);
}
1) whileMystery(3, 5);
2) whileMystery(5, 3);
3) whileMystery(-3, 6);
4) whileMystery(2, 12);
5) whileMystery(-9, 10);