Show the output of the following programs and identify base cases and recursive calls.
public class Test {
public static void main(String[] args) {
System.out.println(
"Sum is " + xMethod(5));
}
public static int xMethod(int n) {
if (n == 1)
return 1;
else
return n + xMethod(n - 1);
}
}
public class Test {
public static void main(String[] args) {
xMethod(1234567);
}
public static void xMethod(int n) {
if (n > 0) {
System.out.print(n % 10);
xMethod(n / 10);
}
}
}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.