The mistake must be in main().
Testing early makes this obvious.
The loop condition is 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:
C:\Source> javac FactorialTester.java C:\Source> 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 C:\Source>
Is main() working as it should?