While Loop Simulation

Category: Simulation
Author: Stuart Reges
Book Chapter: 5.1
Problem: While Loop Simulation
	Consider the following method: 

public static int mystery(int x, int y) {
	int z = 0;
	while (y > 0) {
		z = z + x;
		x = x + y;
		y--;
	}
	return z;
}


	For each call below, indicate what value is returned: 
1) mystery(6, 0)
2) mystery(8, 1)
3) mystery(3, 3)
4) mystery(4, 2)
5) mystery(1, 4)