Given the following program that uses a recursive method guessMyFunction called from the main progam:
Source code: runTests.java
|
import java.util.Scanner;
public class runTests {
public static int guessMyFunction (int n) {
if (n < 0)
return -guessMyFunction (-n);
else if (n < 10)
return (n + 1) % 10;
else
return 10 * guessMyFunction (n / 10) + (n + 1) % 10;
}
public static void main(String[] args) {
int[] testData = {7, 42, -790, 89294};
int val = 0;
for (int i=0; i
|
|
Answer the folling questions:
Q 4: | When the program is executed from the following command line: java runTests
the main progam will loop through the array named testData, and call guessMyFunction with each element.
Trace the values of guessMyFunction when called with a 0, 1, 2, 3, 4 and -1 and then identify what the program output when the main program is executed.
|
|
|