The mistake must be in main()
.
Testing early makes this obvious.
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 ?
Is main()
working as it should?