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

Answer:

The mistake must be in main(). Testing early makes this obvious.


Mistake Fixed

Someone got the loop wrong. It was easy to find this problem since there is only one loop.

Here is the fix:

while ( N >= 0 )

Here is a test run of the program after the fix:

? javac FactorialTester.java
? java FactorialTester
To exit, enter a negative value
Enter N: 0
factorial is 1
Enter N: 1
factorial is 1
Enter N: 7
factorial is 1
Enter N: 25
factorial is 1
Enter N: -1
?

QUESTION 6:

Is main() working as it should?


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