1
Recursion I
Methods that call themselves
About the project
- For the Movie class
– In equals be sure to test all cases
- When the other object is not a Movie
- When the other object is null
- When the other object is a Movie and some of it’s
members are null.
Reminder
- 1st Exam
– Wednesday – Will cover
- Inheritance
- Exceptions
- I/O
– 10-20 questions – Variety of question types
- Short answer
- Fill in the code
- Step through the code
- Perhaps some multiple choice
Recursive Functions
- A recursive function is a function that is
defined in terms of itself.
– Example: factorial
}
- therwise
1 if )! 1 ( * 1 ! { = − = n n n n
Recursive Functions
- Example: Factorial
4! = 4 * 3! = 4 * (3 * 2!) = 4 * (3 * (2 * 1!)) = 4 * (3 * (2 * (1 * 1)))) = 24
Recursive Methods
- A recursive method is one that can call
itself
Non-recursive
methodA() { … methodB (); … }
Recursive
methodB() { … methodB (); … }