While Loop Simulation
Category: Simulation
Author: Alan Borning and Dan Grossman
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 n) { int x = 0; int y = 1; while(n > x && n > y) { n--; x = x + 2; y = y + x; } System.out.println(x); }
1) whileMystery(5);
2) whileMystery(10);
3) whileMystery(4);