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

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

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

QUESTION 7:

Are we done testing this program?


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