Solved

While Loop Simulation
for Each Call of the Method Below

Question 5

Essay

While Loop Simulation
For each call of the method below, write the output that is produced:
public static void mystery(int a, int b) {
while (b != 0) {
if (a > b) {
System.out.print(a + " ");
a = a - b;
} else {
System.out.print(b + " ");
b = b - a;
}
}
System.out.println(a);
}
 Method Call Output  mystery (42,0);       mystery (6,12);       mystery (18,27);       mystery (24,60);       mystery (50,15);      \begin{array}{l}\underline{ \text { Method Call } }& \underline{ \text {Output }} \\\text { mystery }(42,0) ; & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(6,12) ; & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(18,27) ; & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(24,60) ; & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(50,15) ; & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions