Java Reference
In-Depth Information
d.
mystery1(4);
e.
mystery1(16);
f.
mystery1(30);
g.
mystery1(100);
4.
Consider the following method:
public static void mystery2(int n) {
if (n > 100) {
System.out.print(n);
} else {
mystery2(2 * n);
System.out.print(", " + n);
}
}
For each of the following calls, indicate the output that is produced by the method:
a.
mystery2(113);
b.
mystery2(70);
c.
mystery2(42);
d.
mystery2(30);
e.
mystery2(10);
5.
Consider the following method:
public static void mystery3(int n) {
if (n <= 0) {
System.out.print("*");
} else if (n % 2 == 0) {
System.out.print("(");
mystery3(n - 1);
System.out.print(")");
} else {
System.out.print("[");
mystery3(n - 1);
System.out.print("]");
}
}
For each of the following calls, indicate the output that is produced by the method:
a.
mystery3(0);
b.
mystery3(1);
c.
mystery3(2);
d.
mystery3(4);
e.
mystery3(5);
Search WWH ::
Custom Search