Question: Lab Exercises Chapter 5 - Recursion Lab Objective: To practice the students on how to write a recursive method; compare between a recursive and a
Lab Exercises
Chapter Recursion
Lab Objective: To practice the students on how to write a recursive method;
compare between a recursive and a none recursive definition of the
same method.
Q Write a class factorial that contains a recursive and a nonrecursive methods to return the
factorial of a given number.
Where the factorial of is calculated using the following law
for
Q Write a class PalindromeCheck that contains a recursive and a nonrecursive methods to
check a given string input is palindrome or not.
Where a string is palindrome if it can be read from left to right as it can be read from right to
left. eg AdA is palindrome
rrrrrrrrrrrr is palindrome
salsa is not palindrome
hhhtthhh is palindrome
ABCDEDCBA is palindrome
Q Write a class ReverseString that contains a recursive and a nonrecursive methods to
reverse a given string.
input output
abcd dcba
Ahmed demha
Q Write a class Fibonacci that contains a recursive and a nonrecursive methods to
calculate the fibonacci number for a given input
Where Fibonacci is the sequence of numbers
dots..
which is governed by the following law
Fib
Fib
FibFibFib
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
