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. nice explainations for the beginners like me :)
View Tutorial          By: Divya Taneja at 2012-02-11 13:17:17

2. hi guys,

i want some

View Tutorial          By: THANGA at 2012-03-19 15:24:38

3. I am using my NOKIA 2700 via blutooth connection.
View Tutorial          By: Rahi at 2010-05-11 04:39:33

4. error :

Object reference not set to

View Tutorial          By: Ramnath at 2011-05-30 04:01:32

5. hi I want to send SMS to mutiple no.s. Is it possi
View Tutorial          By: gaurav at 2011-05-17 09:54:12

6. I successfully connect to mysql server using:

View Tutorial          By: Arsalan at 2012-07-09 16:38:49

7. Nice Intro .......
View Tutorial          By: MohanRaja at 2012-06-28 11:02:40

8. great explaination !!!
View Tutorial          By: aman at 2012-10-02 06:55:55

9. pLZ LET US FIND SOME PROGRAMS INVOLVING CONVERSION
View Tutorial          By: Ishaq at 2009-02-12 00:27:59

10. hi....can anybody help me....
i need the co

View Tutorial          By: nithin ms at 2007-02-23 08:34:01