Yes. Of course, the stub returns the same value for all N
, but we are not debugging that module, yet.
Now that main()
is correct we can work on factorial.
The factorial method is a separate module.
Its parameter num
is a int
and it returns a long
.
Parameters in Java are always call by value,
which means that when factorial(int num)
is called,
the value from the invocation (in main) is copied into the parameter.
Here is the code:
// Calculate num factorial public static long factorial( int num ) { long fct = 1; for ( int j=1; j<=num; j++ ) fct *= j; return fct; }
Are we done testing this program?