I'm studying java programming by going through Computer Science at the Saylor academy's webpage. I got to the point where I'm learning about debugging programs in NetBeans, and there is a program that computes and prints the factorial of n (=1*2*3*...*n)
. The text says that there is a logical error in the program but nothing about where it is. And I can't seem to figure out where the logical error is.
Anyone who can help? The program code:
/** Compute the factorial of n */
public class Factorial {
// Print factorial of n
public static void main(String[] args) {
int n = 20;
int factorial = 1;
// n! = 1*2*3...*n
for (int i = 1; i <= n; i++) {
factorial *= i;
}
System.out.println("The Factorial of " + n + " is " + factorial);
}
}