by Dinesh Thakur Category: Control Structures

Factorial Number is the product of natural numbers from one to that particular number.  Mathematically, n! = 1 * 2 * 3 * .... * (n-1) * n

Algorithm for Factorial of the Given Number:


step 1: Set fact= 1

step 2: Read b

step 3: Set c=b

step 4: Repeat through step-6 until (c > 0)

step 5:  fact=fact*c

step 6:  c=c-1

step 7: Print fact

step 8: Exit


Here is the Java Example for Factorial of the Given Number:

import java.util.Scanner;
public class FactorialNumber
         public static void main(String ars[])
               int fact=1,b,c;
            Scanner s=new Scanner(;
            System.out.print("Enter A Number for get Factorial : ");
                            c-- ;
            System.out.println("Factorial of "+b+" is : "+fact);

Factorial of the Given Number


/* Factorial Program in Java using BufferedReader */

class FactorialBufferedReader
    public static void main(String args[] )
    throws IOException
        BufferedReader fact = new BufferedReader(new InputStreamReader (;
        String m;
        int n,s=1,i;
        System.out.print("Enter a Number : ");
        System.out.println("Factorial is : "+s);

Factorial Program in Java Using BufferedReader

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles