bob bob - 1 year ago 131
Java Question

Basic recursive method - factorial

I am practicing recursion and I can't see why this method does not seem to work.
Any ideas?

public void fact()

public int fact(int n)
if(n == 1){
return 1;
return n * (fact(n-1));


Answer Source

Your code seems to work but you are not doing anything with the returned value, put method call fact or fact(5) inside of a System.out.println and see what you get.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download