Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Want to get the value that's being returned to a function call

I'm interested in looking under the hood better to learn more about how the compiler works. The problem is, I'm too unlearned about how to get that information.

In the below example, how do I get the result that's being passed to f.fact(5). Also, how do I get the result that's being passed to fact?

Thanks!

Recursion.java

class Recursion {

public static void main (String args[]) {

Factorial f =new Factorial();

System.out.println("Factorial of 5 is " + f.fact(5));

}

class Factorial {

int fact(int n) {

int result;

if ( n==1) return 1;
System.out.println("After if statement n is "+n);
result = fact (n-1) * n;
System.out.println("After calculation and before result return result is "+result+" and n is "+n);
return result;
}

}
Sign In or Register to comment.