Subject: recursion in a Java

From: Geoffrey Fox <[email-masked]>
Date: Sun, 31 Oct 1999 20:18:48 -0500

>From java-for-cse-owner  Sun Oct 31 15:55:12 1999
From: "Troy Barlow" <[email-masked]>
To: <[email-masked]>
Subject: 
Date: Sun, 31 Oct 1999 15:55:49 -0500

This is a multi-part message in MIME format.

- ------=_NextPart_000_0004_01BF23B8.66D2AA20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have a general question about programming with recursion in a Java =
Application. How do I print out the product so far for a problem that =
finds the factorial of a number. Example (3! =3D 3x2x1). I want it to =
print out the 1, the 2, and the 3; not just the 3. This is the code I =
have, but I don't know how to make it show each of the values-it just =
shows the final value.

public int findFactorial(int num)
{
    if(num<=3D1)
        return 1;
    else
        return (num*findFactorial(num-1));
}

Thanks. For the help.

- ------=_NextPart_000_0004_01BF23B8.66D2AA20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3612.1700"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>I have a general question about =
programming with=20
recursion in a Java Application. How do I print out the product so far =
for a=20
problem that finds the factorial of a number. Example (3! =3D 3x2x1). I =
want it to=20
print out the 1, the 2, and the 3; not just the 3. This is the code I =
have, but=20
I don't know how to make it show each of the values-it just shows the =
final=20
value.</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>public int findFactorial(int=20
num)<BR>{<BR>&nbsp;&nbsp;&nbsp;=20
if(num&lt;=3D1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
1;<BR>&nbsp;&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
return (num*findFactorial(num-1));<BR>}</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>Thanks. For the =
help.</FONT></DIV></BODY></HTML>

- ------=_NextPart_000_0004_01BF23B8.66D2AA20--

------- End of Forwarded Message