Yes. Of course, the stub returns the same value for all N
, but we are not debugging that module, yet.
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; }
Would it be desirable to test this method by itself, without other methods that might get in the way?