Analyze the following two programs:
```
A:
public class Test {
public static void main(String[] args) {
xMethod(5);
}
public static void xMethod(int length) {
if (length > 1) {
System.out.print((length - 1) + " ");
xMethod(length - 1);
}
}
}
B:
public class Test {
public static void main(String[] args) {
xMethod(5);
}
public static void xMethod(int length) {
while (length > 1) {
System.out.print((length - 1) + " ");
xMethod(length - 1);
}
}
}
```
a. The two programs produce the same output 5 4 3 2 1.
b. The two programs produce the same output 1 2 3 4 5.
c. The two programs produce the same output 4 3 2 1.
d. The two programs produce the same output 1 2 3 4.
e. Program A produces the output 4 3 2 1 and Program B prints 4 3 2 1 1 1 .... 1 infinitely.
e. Program A produces the output 4 3 2 1 and Program B prints 4 3 2 1 1 1 .... 1 infinitely.
In Program B, xmethod(5) invokes xmethod(4), xmethod(4) invokes xmethod(3), xmethod(3) invokes xmethod(2), xmethod(2) invokes xmethod(1), xmethod(1) returns control to xmethod(2), xmethod(2) invokes xmethod(1) because of the while loop. This continues infinitely.
You might also like to view...
Using Access Objects can expedite the process of converting data into information
Indicate whether the statement is true or false
A(n) port is the equivalent of a network channel or connection point in a data communications system. _________________________
Answer the following statement true (T) or false (F)