Question
Show what would be displayed by the following calls to the recursive method (DO NOT run the program) a) int recur(int n) { if (n
Show what would be displayed by the following calls to the recursive method (DO NOT run the program)
a)
int recur(int n)
{
if (n < 0)
return 1;
else if (n < 10)
return 1;
else
return (1 + recur (n / 10));
}
What would be displayed by the following calls?:
System.out.println(recur(5));
System.out.println(recur(25));
System.out.println(recur(250));
b)
int recur2(int n)
{
if (n < 0)
return 1;
else if (n < 10)
return n;
else
return ((n % 10) + recur2(2 / 10 ));
}
What would be displayed by the following calls?:
System.out.println(recur2(5));
System.out.println(recur2(25));
System.out.println(recur2(250));
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started