While Loop Simulation
Category: Simulation
Author: Marty Stepp and Ruth Anderson
Book Chapter: 5.1
Problem: While Loop Simulation
For each call below to the following method, write the output that is printed, as it would appear on the console: public static void mystery(int n) { int x = 2; while (x < n) { if (n % x == 0) { System.out.print(x + " "); n = n / x; x = 2; } else { x++; } } System.out.println(n); }
1) mystery(1)
2) mystery(6)
3) mystery(21)
4) mystery(24)
5) mystery(120)