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

Answer:

Yes. Static methods can call other static methods.

Yes. Static methods pass data to other static methods through parameters, using call by value.


Factorial (Again!)

flowchart of factorial

Recall factorial from chapter 21 (and likely from many math courses):

(N Factorial) = N! = 
   N×(N-1)×(N-2)×(N-3)× . . . 4×3×2×1

N must be a positive integer or zero, and 0! is defined to be 1. For example,

 
6! = 6 × 5 × 4 × 3 × 2 × 1 = 720
Let us write a program that repeatedly asks the user for N, computes N!, prints it out, and asks for another N. The user signals the end of input by entering a negative value.

The flowchart shows the design for the program.


QUESTION 3:

What happens if the first N the user enters is negative?


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