go to previous page   go to home page   go to next page

Answer:

Yes. Of course, the stub returns the same value for all N, but we are not debugging that module, yet.


Factorial Method

flowchart of factorial method

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;
  }

QUESTION 7:

Would it be desirable to test this method by itself, without other methods that might get in the way?


go to previous page   go to home page   go to next page