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 > 2) { x = x + y; y = x - y; n--; } System.out.println(x); } For each call below, indicate what output is produced.
1) mystery(1);
2) mystery(3);
3) mystery(5);
4) mystery(7);