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 y) { int x = 0; int z = 0; while (y > 0) { x++; z = z + y % 10; y = y / 10; } System.out.println(x + " " + z); } For each call below, indicate what output is produced.
1) mystery(8);
2) mystery(32);
3) mystery(184);
4) mystery(8239);