import java.util.Scanner;

public class Factorial{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.println(“Enter the number whose factorial you want: “);
        int n = in.nextInt();
        int f =1;
        for(int i=n; i>0; i–){
            f = f*i;
        }
        System.out.println(“Factorial of “+n+” is “+f);
}
}

output

Enter the number whose factorial you want: 
6
Factorial of 6 is 720

 

Source: http://selenium-makeiteasy.blogspot.com