Java Program to Find Factorial of Number

« Previous Program Next Program »

Find Factorial of a Number

To find the factorial of any number in Java Programming, you have to ask to the user to enter the number, now find the factorial of the entered number using for loop and display the factorial result of the given number on the output screen as shown in the following program.

Java Programming Code to Find Factorial of Number

Following Java Program ask to the user to enter a number to find its factorial, then display the factorial result on the screen :

/* Java Program Example - Find Factorial of a Number */
import java.util.Scanner;

public class JavaProgram
    public static void main(String args[])
        int num, i, fact=1;
        Scanner scan = new Scanner(;
        System.out.print("Enter a Number : ");
        num = scan.nextInt();
        for(i=num; i>0; i--)
            fact = fact*i;
        System.out.print("Factorial of " + num + " is " + fact);

When the above Java Program is compile and executed, it will produce the following output:

Java Program find factorial of number

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.