Factorial Code Snippet

Here's a Java code example for Factorial. In this example, we will compute for the Factorial of 6 which is denoted by variable n:

int n = 6; // where n is a non-negative integer
int count=1, product=1, factor=1;
do{
product = product * factor++;
count++;
}while(count <= n);

System.out.println(n + "! = " + product);

1 comment: