import java.io.*;
import java.lang.*;

class Factorial
{
    public static void main(String args[]) throws IOException
    {
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        System.out.println("Enter Number: ");
        int num=Integer.parseInt(br.readLine());

        int result = 1;
        while(num>0)
        {
            result = result * num;
            num--;
        }
        System.out.println("Factorial of Given Number is : "+result);
    }
}

 OUTPUT:

javac Factorial.java
 
java Factorial
 
Enter Number:
6
Factorial of Given no. is : 720

Buy Head First Java

Best Book for Java

Beginner's Book