Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions