Comment on Tutorial - Recursion in java By aathishankaran



Comment Added by : Søren

Comment Added at : 2011-09-22 03:13:53

Comment on Tutorial : Recursion in java By aathishankaran
Now what the hell does all this mean???
To better understand how the fact() method works, letâs go through a short example. When you compute the factorial of 3, the first call to fact() will cause a second call to be made with an argument of 2. this invocation will cause fact() to be called a third time with an argument of 2. This call will return 1, which is then be called a third time with an argument of 1. This call will return1, which is then multiplied by 2 (the value of n in the second invocation). This result (which is 2) is then returned to the original invocation of fact() and multiply by 3 ( the original value of n). This yields the answer, 6. You might find it interesting to insert println() statements into fact() which will show at what level each call is and what the intermediate answers are.


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Please assist me in getting the code to read messa
View Tutorial          By: Jaydatta at 2009-04-05 23:24:57

2. i have been trained in java stream. But i dont kno
View Tutorial          By: savio at 2013-01-23 10:15:51

3. Good example. However as someone said, it would be
View Tutorial          By: Neo Cambell at 2010-03-10 11:02:06

4. really nice
View Tutorial          By: umer at 2011-06-25 06:35:19

5. really helpfull :) thanks
View Tutorial          By: Jagan at 2014-12-09 10:16:56

6. javax.comm.NoSuchPortException
at javax.co

View Tutorial          By: vijay at 2013-12-03 07:32:38

7. frnds i need overriding concept in bubble sort
View Tutorial          By: rabbu at 2014-08-21 12:46:52

8. hi.I am new in j2me and really want to learn more
View Tutorial          By: A.vinothKumar at 2012-08-20 07:50:26

9. I wish to implement geocoding and reverse geocodin
View Tutorial          By: Leni at 2010-02-25 13:45:41

10. This is the help full sites for diploma student
View Tutorial          By: Tanuja at 2013-08-11 09:41:55