Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes Recursive method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursive method" Watch "Recursive method" New topic

Recursive method

Stephanie Dears
Ranch Hand

Joined: May 26, 2005
Posts: 43
How do determine the recursive formula?

I have the following code that I need to rewrite into a recursive method:

I understand this code, and I understand the theory of recursion. I even understand the factorial and Fibonacci recursion code. But I'm dealing with two sets of numbers here and I'm confused.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39547
This sounds like homework of some kind.

Recursion works by reducing a problem to a simpler problem of the same kind. What you need to do is reduce intDiv(n1, n2) to intDiv(n1-n2, n2), and terminate as appropriate.

Is it the fact that two numbers are involved that confuses you? That should be familiar if you have programmed Fibonacci recursively. Another example you could study is Euclid's GCD algorithm.
[ January 01, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
I agree. Here's the link:
subject: Recursive method
Similar Threads
equals method .. comparing objects
TIJ 3 problem at simpeltest
trouble with operator
problem with java code
exponent loop w/out math .pow.